<?php
                use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable; 
       
       function PFBC_Load($class) {
    $file =  pluginpath."/PFBC/" . str_replace("_", DIRECTORY_SEPARATOR, $class) . ".php";
    if(is_file($file))
        include_once $file;
}
spl_autoload_register("PFBC_Load");
if(in_array("__autoload", spl_autoload_functions()))
spl_autoload_register("__autoload");


        function PFBC_Load_Plugins($class) {
   
                $file =  includepath."/" . str_replace("_", DIRECTORY_SEPARATOR, $class) . ".php";
                
                if(is_file($file))
                    include_once $file;
         }
spl_autoload_register("PFBC_Load_Plugins");
if(in_array("__autoload", spl_autoload_functions()))
spl_autoload_register("__autoload");

     
        class model extends configdata { 


           function __construct($db_exec="",$userdata=array(),$post='')
           {
             global $info,$memcache;
             
             
             if($_COOKIE['oauth'])
             {
             $this->userdata=$_COOKIE;
             }else
             {
             $this->userdata=array();
             }
             
             if(count($userdata))
             {
            $this->userdata =$userdata;
             
             }
            
           
             if($post)
             {
             
             $this->post=$post;
             }
             
             
             if($db_exec)
             {
             $this->db=$db_exec; 
             
             }else
             {
             $db_exec = new db_execute(); 
             $db_exec->set_host(db_host);
             $db_exec->set_user(db_user);
             $db_exec->set_pass(db_pass); 
             $db_exec->set_database(db_name);
             $this->db=$db_exec; 
             $this->db->get_connect();
             $this->close=1;

             if($_GET['oauth'])
             {
             
             $this->userdata=$this->getuserbyoauth($_GET['oauth']);
             if($this->userdata['userid'])
             {
             
                  
           foreach($this->userdata as $keyuser =>$valueuser)
           {
                   if("imgmid"==$keyuser)
                   {
                   
                        $imgarray=$this->getimagebyimgmid($valueuser);

                        setcookie("imguser",$imgarray['newpath'], $time, "/",$domain);
                        setcookie("width",$imgarray['width'], $time, "/",$domain);
                        setcookie("height",$imgarray['height'], $time, "/",$domain);
                        $this->userdata['imguser']=$imgarray['newpath'];
                        $this->userdata['width']=$imgarray['width'];
                        $this->userdata['height']=$imgarray['height'];
                   
                   }else if("simgmid"==$keyuser)
                   {
                        $imgarray=$this->getimagebyimgmid($valueuser);

                        setcookie("simguser",$imgarray['newpath'], $time, "/",$domain);
                        setcookie("thumbwidth",$imgarray['width'], $time, "/",$domain);
                        setcookie("thumbheight",$imgarray['height'], $time, "/",$domain);
                        $this->userdata['simguser']=$imgarray['newpath'];
                        $this->userdata['thumbwidth']=$imgarray['width'];
                        $this->userdata['thumbheight']=$imgarray['height'];
                   
                   
                   }
                   
                   
                       //$this->arraydata['data'][$keyuser]=$valueuser;
                       setcookie($keyuser,$valueuser, $time, "/",$domain);
              
           
           
           
           }
           
             
             $_COOKIE=$this->userdata;
             }
             
             
             }
             
             
             if($_POST['oauth'])
             {
             $this->userdata=$this->getuserbyoauth($_POST['oauth']);
             
             
             }
             
             } 
             
             $this->memcache=$memcache;
             
             
             //echo "1"."<br>";
             
             
               
             
             
             $this->info=$info;
             
             
             
             
           }
           
           function loginuser($username,$email,$password,$syncf=0)
           {
           $where=array();
           $md5password=md5($password.'-123456');
           $oldpassword=md5(strtolower($username) . $password);
           
           
           if (defined('canonalgologin'))
            {
             
             
             $where[]=" (password='".$md5password."' or password='".$oldpassword."' or password='".md5($password)."' or password=md5(concat('".$password."', `salt`)) ) ";
            
            }
            else
            {
            $where[]=" (password='".$md5password."' or password='".$oldpassword."') ";
            
            }

           
           
           $where[]=" status=1 ";
           
           if($username)
           {
           $where[]=" username='".$username."' ";
           }else if($email)
           {
           $where[]=" email='".$email."' ";
           }
           
           if($syncf)
           {
           if($_COOKIE['userid'])
           {
              $where[]=" syncfacebook=0 and userid !=".$_COOKIE['userid'];
           }else
           {
                $where[]=" syncfacebook=0 ";
           
           }
           
           
           }
           
           $wherestr="";
           if(count($where))
           {
           $wherestr=" where ".join(" and ",$where);
           
           }
           
           $sql="select username,displayname,oauth,imgmid,simgmid,userid,tb_user.status,tb_user.roleid from tb_user  $wherestr ";
         //  if($_GET['email']=="ijui555@hotmail.com")
//           {
//           echo 'sql->'.$sql."\n";
//           echo 'username->'.$username."\n";
//           echo 'emai->'.$email."\n";
//           exit;
//           
//           }

           
           $arrayuser=$this->db->db_set_recordset($sql);
           
           
           
           if($arrayuser[0]['userid'])
           {
            if (defined('canonalgologin'))
            {
            $sql="select * from tb_serial where createby='".$arrayuser[0]['userid']."' and serial<>'' ";
            $arraycheck=$this->db->db_set_1recordrow($sql);
            
            
            $arrayuser[0]['model']='';
            if($arraycheck['serial'])
            {
            
            $arrayuser[0]['model']=$this->gotocheck($arraycheck['serial'],1);
            
            
            }
            
        //    gotocheck($serial,$getstatus=0)
            
            }
           
           return $arrayuser[0];
           
           }else
           {
           
           return false;
           
           }
           
           
           }
           
           function loginfacebook($facebookid,$email="",$firstname="",$lastname="",$gender="",$userid=0)
           {
           $sql="select username,displayname,oauth,imgmid,simgmid,userid,tb_user.status,tb_user.roleid from tb_user where  facebookid='$facebookid' ";
           $arrayuser=$this->db->db_set_1recordrow($sql);
           
           if($arrayuser['userid']&&$userid==0)
           {
           
           return $arrayuser;
           
           }else
           {
           
          
           
           $arraydata['facebookid']=$facebookid;
           
           if($userid==0)
           {
           $arraydata['username']='facebook-'.$facebookid;
           
           }
           
           $arraydata['displayname']=$firstname.' '.$lastname;
           $arraydata['firstname']=$firstname;
           
           if($gender)$arraydata['gender']=$gender;
           
           $arraydata['lastname']=$lastname;
           $arraydata['emailfacebook']=$email;
           if($userid==0)
           {
           $newpassword=substr(md5(mktime().$arraydata['username'].$arraydata['email']),0,10);
           
           $arraydata['password']=md5($newpassword.'-123456');
           $arraydata['oauth']=md5(mktime().$newpassword);
           }
           if(defined('privatedomain')&&privatedomain==1)
            {
            
            }else
            {
           $arraydata['status']=1;
            }
           
           if(defined('loginfacebookwhenprivate')&&loginfacebookwhenprivate==1) 
           {
           
           $arraydata['status']=1;
           
           }
            
           
            if($userid==0)
           {
           $arraydata['createdate']=date("Y-m-d H:i:s");
           
           $this->db->db_set($arraydata,"tb_user");
           $userid=$this->db->db_get_last_number();
           }else
           {

           $arraydata['syncfacebook']=1;
           $arraydata['syncuser']=1;
           
        
           $this->db->db_set($arraydata,"tb_user",' userid='.$userid);
           if($arrayuser['userid'])
           {
           $sqldelete='delete from tb_user where userid='.$arrayuser['userid'];
           $this->db->db_delete($sqldelete);
           
           }
           
           
           }
           
           //$this->savescoredata($userid,2);
           $this->savegamenictaionbygxcid($userid,2);
           
              if(!is_dir(imgpath.'/user/'.$userid))
                     {
                      mkdir(imgpath.'/user/'.$userid,0777);
                      chmod(imgpath.'/user/'.$userid,0777);
                      }
                      
              $newfie=mktime().'-'.rand(0,100000).'.jpg'; 
              $file=imgpath.'/user/'.$userid.'/'.$newfie;
              if (!is_file($file))
                    {
                    $img=@file_get_contents('https://graph.facebook.com/' . $facebookid . '/picture?type=large');
                    @file_put_contents($file, $img);
                    chmod($file, 0777);
                    }
           
           
           $dataArray=array();
           $dataArray['avatar']=$userid;
           $dataArray['createby']=$userid;
           $dataArray['updateby']=$userid;
           $dataArray['createdate']=date("Y-m-d H:i:s");
           $dataArray['cache']=0;
           $dataArray['status']=1;
           $dataArray['conid']=34;
           list($width, $height, $type, $attr) = getimagesize($file);
           $dataArray['basewidth']=$width;
           $dataArray['baseheight']=$height;
           $dataArray['width']=$width;
           $dataArray['height']=$height;
           $dataArray['path']=str_replace(rootpath.'/','',$file);
           $dataArray['size']=filesize($file);
           $dataArray['url']='https://graph.facebook.com/' . $facebookid . '/picture?type=large';
           $dataArray['imgname']=$newfie;
           $dataArray['name']=$newfie;
           $imgmid=$this->saveimagedata($dataArray);
           
              $newfie=mktime().'-'.rand(0,100000).'.jpg';; 
              $file=imgpath.'/user/'.$userid.'/'.$newfie;
              if (!is_file($file))
                    {
                    $img=@file_get_contents('https://graph.facebook.com/' . $facebookid . '/picture?width=300&height=300');
                    @file_put_contents($file, $img);
                    chmod($file, 0777);
                    }
           
           
           $dataArray=array();
           $dataArray['avatar']=$userid;
           $dataArray['createby']=$userid;
           $dataArray['updateby']=$userid;
           $dataArray['createdate']=date("Y-m-d H:i:s");
           $dataArray['cache']=0;
           $dataArray['status']=1;
           $dataArray['conid']=33;
           list($width, $height, $type, $attr) = getimagesize($file);
           $dataArray['basewidth']=$width;
           $dataArray['baseheight']=$height;
           $dataArray['width']=320;
           $dataArray['height']=320;
           $dataArray['path']=str_replace(rootpath.'/','',$file);
           $dataArray['size']=filesize($file);
           $dataArray['url']='https://graph.facebook.com/' . $facebookid . '/picture?width=300&height=300';
           $dataArray['imgname']=$newfie;
           $dataArray['name']=$newfie;
           $simgmid=$this->saveimagedata($dataArray);
           
           $arraydata2['imgmid']=$imgmid;
           $arraydata2['simgmid']=$simgmid;
           $this->db->db_set($arraydata2,"tb_user"," userid=".$userid);          
           $arraynewdata['username']=$arraydata['username'];
           $arraynewdata['displayname']=$arraydata['displayname'];
           $arraynewdata['oauth']=$arraydata['oauth'];
           $arraynewdata['userid']=$userid;
           $arraynewdata['imgmid']=$imgmid;
           $arraynewdata['simgmid']=$simgmid;
           $arraynewdata['status']=$arraydata['status'];
           $arraynewdata['hasuser']=0;
           $arraynewdata['roleid']=1;
           $arraynewdata['userto']=0;
           if($arrayuser['userid'])
           {
           
           $arraynewdata['hasuser']=1;
           $arraynewdata['userto']=$arrayuser['userid'];
           }
           
           
           
           
           
           return $arraynewdata;
           //$file=imgpath.'/user/'.$userid.'/'.$newfie;
                    
           
           
           
           
           
           
           

             
           
           
           }
           
           }
           
           function getimagebyimgid($imgid,$conid=0,$width="",$height="",$imgmid="")
           {
              
           $where=array();
           $where[]=" imgid='".$imgid."' ";
           
           
           if($conid)
           {
           $where[]=" conid=".$conid." ";
           }
           
           
           if($width)
           {
           $where[]=" width=".$width." ";
           }
           
           
           if($height)
           {
           $where[]=" height=".$height." ";
           }
           
          
           
          
           
           
           $wherestr="";
           if(count($where))
           {
           $wherestr=" where ".join(" and ",$where);
           }
           
           
           $sql="select * from tb_img $wherestr  order by updatedate desc ";
           $arrayimage=$this->db->db_set_recordset($sql);
           
           if($arrayimage[0]['imgmid'])
           {
           if($arrayimage[0]['url'])
           {
           $path=baseinfo.'/'.$arrayimage[0]['path'];
           }else if($arrayimage[0]['path'])
           {
           $path=baseinfo.'/'.$arrayimage[0]['path'];
           }else
           {
           $path=imgdefaultinfo.'/noimage.png';
           }
           
           $arrayimage[0]['newpath']=$path;
           return $arrayimage[0];
           }
           else
           {
           

           
           if($width&&$height)
           {
           $sql="select * from tb_img where imgid=$imgid and conid=6   ";
           $arrayimage=$this->db->db_set_recordset($sql);
           
            

           
           if($arrayimage[0]['imgmid'])
           {
           $check=0;
             if($arrayimage[0]['path'])
           {
           $check=2;
           $path=rootpath.'/'.$arrayimage[0]['path'];
           }
           else
           {
           $check=0;
           $newpath=imgdefaultpath.'/noimage-'.$width.'x'.$height.'.jpg';
           $path=imgdefaultpath.'/noimage.png';
             
          // file_get_contents(plugininfo.'/showimages.php?source='.$path.'&width='.$width.'&height='.$height);
           if(!is_file($newpath))
           {
           
           $this->cropimage($path,$width,$height,$newpath);
           }

           
           $newpath=imgdefaultinfo.'/noimage-'.$width.'x'.$height.'.jpg';
           $arrayimage[0]['newpath']=$newpath;
           $arrayimage[0]['width']=$width;
           $arrayimage[0]['height']=$height;
           return $arrayimage[0];
           
           }
           
           
           
           
           if($check)
           {
              if($check==2&&is_file($path))
              {
              
              
            //  file_get_contents(plugininfo.'/showimages.php?source='.$path.'&width='.$width.'&height='.$height);
              
              $this->cropimage($path,$width,$height);
              
              $arraydataset['imgname']=$arrayimage[0]['imgname'];
              if(is_file(rootpath.'/'.$arrayimage[0]['path']))
              {
              $arraydataset['imgid']=$imgid;
              
              list($namefile,$exitfile)=explode(".",$arrayimage[0]['name']);
              
              $arraydataset['name']=$namefile.'-'.$width.'x'.$height.'.'.$exitfile;
              list($namefile,$exitfile)=explode('.',$arrayimage[0]['imgname']);
              $arraydataset['url']="";
              $arraydataset['size']=''.filesize(rootpath.'/'.$arrayimage[0]['path']);
              $arrayimage[0]['path']=str_replace($arrayimage[0]['name'],$arraydataset['name'],$arrayimage[0]['path']);
              $arraydataset['path']=$arrayimage[0]['path']  ;
              $arraydataset['width']=''.$width;
              $arraydataset['height']=''.$height;
              $arraydataset['basewidth']=''.$width;
              $arraydataset['baseheight']=''.$height;
              $arraydataset['conid']=$this->getconditionbysize($width,$height);
              $arraydataset['status']='1';
              $arraydataset['createby']=$arrayimage[0]['createby'];
              $arraydataset['createdate']=date("Y-m-d H:i:s");
              $arraydataset['updateby']=$arrayimage[0]['createby'];
              $arraydataset['updatedate']=date("Y-m-d H:i:s");
              
              $imgmid=$this->saveimagedata($arraydataset);
              $arraydataset['imgmid']=''.$imgmid;
              $arraydataset['newpath']=baseinfo.'/'.$arrayimage[0]['path'];
              return $arraydataset;
              
              }
              else
              {
              $path=imgdefaultinfo.'/noimage-'.$width.'x'.$height.'.jpg';
              $this->cropimage($path,$width,$height);
             // file_get_contents(plugininfo.'/showimages.php?source='.$path.'&width='.$width.'&height='.$height);
              $arrayimage[0]['newpath']=$path;
              $arrayimage[0]['width']=$width;
              $arrayimage[0]['height']=$height;
              return $arrayimage[0];
              
              }
              
              }
              else if($check==1)
              {
              
              
                              
           $is =@getimagesize($path);
           
           if ( $is )
           {
           
         
           
           
          
              
              $exitfile= strtolower(array_pop(explode('.',$arrayimage[0]['url'])));
              //$namefile=mktime().'-'.rand(1,100000).'.jpg';
              
              list($nameoldfile,$exitfile)=explode('.',$arrayimage[0]['name']);
              $newfile2=$nameoldfile.'-'.$width.'x'.$height.'.'.$exitfile;     
              $newpath2=str_replace($arrayimage[0]['name'],$newfile2,$arrayimage[0]['path']);    
              $newpath=rootpath.'/'.$newpath2 ;
              //echo    $newpath;
             // exit;
              $this->cropimage($path,$width,$height,$newpath);
              
             // exit;
              
              $arraydataset['imgname']=$arrayimage[0]['imgname'];
              $arraydataset['imgid']=$imgid;
              $arraydataset['name']=$newfile2;
              $arraydataset['url']=$path;
              $arraydataset['size']=filesize($newpath);
              $arraydataset['path']=$newpath2;
              $arraydataset['width']=''.$width;
              $arraydataset['height']=''.$height;
              $arraydataset['basewidth']=''.$width;
              $arraydataset['baseheight']=''.$height;
              $arraydataset['conid']=$this->getconditionbysize($width,$height);
              $arraydataset['status']=1;
              $arraydataset['createby']=$arrayimage[0]['createby'];
              $arraydataset['createdate']=date("Y-m-d H:i:s");
              $this->saveimagedata($arraydataset);
              $arraydataset['newpath']=baseinfo.'/'.$newpath2;
              return $arraydataset;
              
           }
           else
           {
           
           
           
              $arraydataset['imgname']=$arrayimage[0]['imgname'];
              $arraydataset['imgid']=$imgid;
              $arraydataset['name']=$newfile2;
              $arraydataset['url']=$path;
              $arraydataset['size']=filesize(rootpath.'/'.$arrayimage[0]['path']);
              $arraydataset['path']=baseinfo.'/'.$arrayimage[0]['path'];;
              $arraydataset['width']=''.$width;
              $arraydataset['height']=''.$height;
              $arraydataset['basewidth']=''.$width;
              $arraydataset['baseheight']=''.$height;
              $arraydataset['conid']=$this->getconditionbysize($width,$height);
              $arraydataset['status']=1;
              $arraydataset['createby']=$arrayimage[0]['createby'];
              $arraydataset['createdate']=date("Y-m-d H:i:s");
              $this->saveimagedata($arraydataset);
              $arraydataset['newpath']=baseinfo.'/'.$newpath2;
              return $arraydataset;
           
           
           
           }
              
              
              }
           
           
           }
           
           
           }
           else
           {
           

           
           $check=0;
           $newpath=imgdefaultpath.'/noimage-'.$width.'x'.$height.'.jpg';
           $path=imgdefaultpath.'/noimage.png';
           
          // file_get_contents(plugininfo.'/showimages.php?source='.$path.'&width='.$width.'&height='.$height);
           if(!is_file($newpath))
           {
           
           
           $this->cropimage($path,$width,$height,$newpath);
           }
           
           $newpath=imgdefaultinfo.'/noimage-'.$width.'x'.$height.'.jpg';
           $arrayimage[0]['newpath']=$newpath;
           $arrayimage[0]['width']=$width;
           $arrayimage[0]['height']=$height;
           return $arrayimage[0];
           
           
           }
           
           }else
           {
           
           $path=imgdefaultinfo.'/noimage.png';
           $arrayimage[0]['newpath']=$path;
           return $arrayimage[0];
           
           }
           
           
           }
           
           
           }
           
           function savescoredata($userid,$scoreid)
           {
                            $sql="SHOW TABLES LIKE 'tb_score_data'";
                 $arraycheck=$this->db->db_set_1recordrow($sql);
                 if(count($arraycheck))
                 {
           $sql='SELECT score FROM `tb_score_data` where scoid='.$scoreid;
           $scoredata=$this->db->db_set_1recordrow($sql);
           
           $arraydata=array();
           $arraydata['userid']=$userid;
           $arraydata['score']=$scoredata['score'];
           $arraydata['createdate']=date("Y-m-d H:i:s");
           $arraydata['scoid']=$scoreid;
           
           $this->db->db_set($arraydata,'tb_score_user');
                 }
           
           
           }
           
           function savegamenictaionbygxcid($userid,$gxcid)
           {
           
           if($userid&&$gxcid)
           {
           $sql='select * from tb_game_exp_config where gxcid='.$gxcid;
           $config=$this->db->db_set_1recordrow($sql);
           if($config['exp']!='0')
           {
           
           $sql='select * from tb_game_exp_setting';
           $setting=$this->db->db_set_1recordrow($sql);
           
           $arrayset=array();
           $arrayset['userid']=$userid;
           $arrayset['badge']=1;
           $arrayset['exp']=$config['exp'];
           $arrayset['gxcid']=$gxcid;
           $arrayset['updatedate']=date("Y-m-d H:i:s");
           $arrayset['createdate']=date("Y-m-d H:i:s");
           $this->db->db_set($arrayset,'tb_game_log');
           
           
           
           $arrayset=array();
           $arrayset['userid']=$userid;
           $arrayset['badid']=0;
           $arrayset['levelid']=0;
           $arrayset['level']=0;
           $arrayset['exp']=$config['exp'];
           $arrayset['gxcid']=$gxcid;
           $arrayset['updatedate']=date("Y-m-d H:i:s");
           $arrayset['createdate']=date("Y-m-d H:i:s");
           $this->db->db_set($arrayset,'tb_game_activity');
           
           if($setting['gexpsid'])
           {
           if($setting['status']=='1')
           {
           

           
           $sql="select sum(exp) as sumexp from tb_game_log where userid=".$userid;
           $expdata=$this->db->db_set_1recordrow($sql);
           
           if(intval($setting['exp'])==0)
           {
           $countlevel=0;
           }
           else
           {
           $countlevel=intval($expdata['sumexp'])/intval($setting['exp']);
           }
           
           
           $arrayset=array();
           $sql='select * from tb_game_score where userid='.$userid;
           $gamescore=$this->db->db_set_1recordrow($sql);
           
           
           
           $sql='select sum(exp) as sumexppoint from tb_game_point where userid='.$userid;
           $sumpoint=$this->db->db_set_1recordrow($sql);
           $point=0;
           if($setting['point']=='0'||intval($expdata['sumexp'])==0)
           {
           
           }else
           {
           if($sumpoint['sumexppoint'])
           {
           
           }else
           {
           
           $sumpoint['sumexppoint']=0;
           
           }
           if(intval($setting['point'])>intval($expdata['sumexp']))
           {
           
           }else
           {
           if(intval($sumpoint['sumexppoint'])==0)
           {
           $point=intval(intval($expdata['sumexp'])/intval($setting['point']));
           $mod=intval($expdata['sumexp'])%intval($setting['point']);
         
           $point2=intval($expdata['sumexp'])-$mod;
           $arrayset=array();
           $arrayset['exp']=$point2;
           $arrayset['userid']=$userid;
           
           $this->db->db_set($arrayset,'tb_game_point');
           
           
           }else
           {
           
           if(intval($expdata['sumexp'])>intval($sumpoint['sumexppoint']))
           {
           
           $nowpoint=intval($expdata['sumexp'])-intval($sumpoint['sumexppoint']);
           
           if(intval($setting['point'])>$nowpoint)
           {
           
           }else
           {
           
           
           $point=intval($nowpoint/intval($setting['point']));
           $mod=intval($nowpoint)%intval($setting['point']);
           
           
           $point2=$nowpoint-$mod;
           $arrayset=array();
           $arrayset['exp']=$point2;
           $arrayset['userid']=$userid;
           
           $this->db->db_set($arrayset,'tb_game_point');
          
           }
           
           
           }
           
           
           }
           }
           
           }
           
           
           $arrayset=array();
           $arrayset['level']=$countlevel;
           $arrayset['exp']=intval($expdata['sumexp']);
           $arrayset['levelid']=0;
           
           $arrayset['updatedate']=date("Y-m-d H:i:s");
           
           if($gamescore['gscoid'])
           {
           $arrayset['point']=intval($gamescore['point'])+intval($point);
           $this->db->db_set($arrayset,'tb_game_score',' gscoid='.$gamescore['gscoid']);
           
           }else
           {
           $arrayset['point']=$point;
           $arrayset['userid']=$userid;
           $arrayset['createdate']=date("Y-m-d H:i:s");
           $this->db->db_set($arrayset,'tb_game_score');
           }
           
           if($countlevel>0)
           {
           
           $sql='select * from tb_game_activity where tb_game_activity.level='.$countlevel.' userid='.$userid;
           $badgecheckdata2=$this->db->db_set_1recordrow($sql);
           if($badgecheckdata2['glogid'])
           {
           
           }else
           {
           $arrayset=array();
           $arrayset['userid']=$userid;
           $arrayset['badid']=0;
           $arrayset['levelid']=0;
           $arrayset['level']=$countlevel;
           $arrayset['exp']=0;
           $arrayset['gxcid']=$gxcid;
           $arrayset['updatedate']=date("Y-m-d H:i:s");
           $arrayset['createdate']=date("Y-m-d H:i:s");
           $this->db->db_set($arrayset,'tb_game_activity');
           
           }
           
           }
           
           
           
           $sql="select sum(badge) as sumbadge from tb_game_log where userid=".$userid.' and gxcid='.$gxcid;
           $badgedata=$this->db->db_set_1recordrow($sql);
           $sumbadge=0;
           if($badgedata['sumbadge'])
           {
           $sumbadge=intval($badgedata['sumbadge']);
           
           }
           
           if($sumbadge>0)
           {
           
           $sql='select * from tb_game_badge where gxcid='.$gxcid.' and tb_game_badge.count<='.$sumbadge.' and tb_game_badge.count!=0';
           $badgecheckdata=$this->db->db_set_recordset($sql);
           if(count($badgecheckdata))
           {
           foreach($badgecheckdata as $valuecheck)
           {
           
           $sql='select * from tb_game_activity where tb_game_activity.badid='.$valuecheck['badid'].' and gxcid='.$gxcid.' and userid='.$userid;
           $badgecheckdata2=$this->db->db_set_1recordrow($sql);
           if($badgecheckdata2['glogid'])
           {
           
           
           }else
           {
           $arrayset=array();
           $arrayset['userid']=$userid;
           $arrayset['badid']=$valuecheck['badid'];
           $arrayset['levelid']=0;
           $arrayset['level']=0;
           $arrayset['exp']=0;
           $arrayset['gxcid']=$gxcid;
           $arrayset['updatedate']=date("Y-m-d H:i:s");
           $arrayset['createdate']=date("Y-m-d H:i:s");
           $this->db->db_set($arrayset,'tb_game_activity');
           
           }
           
           
           }
           }
           
           }
           
           
           
           
           
           
           }
           else if($setting['status']=='2')
           {
           
           
           
           $sql="select sum(exp) as sumexp from tb_game_log where userid=".$userid;
           $expdata=$this->db->db_set_1recordrow($sql);
           
        
           $sql='SELECT * FROM `tb_game_level` where tb_game_level.exp<='.intval($expdata['sumexp']).'  order by tb_game_level.exp    desc limit 0,1';
           //echo $sql;
           
           $checklevel=$this->db->db_set_1recordrow($sql);
           $levelid=0;
           if($checklevel['levelid'])
           {
           
           $sql='select * from tb_game_activity where tb_game_activity.levelid='.$checklevel['levelid'].' and userid='.$userid;
           $badgecheckdata2=$this->db->db_set_1recordrow($sql);
            if($badgecheckdata2['glogid'])
           {
           $levelid=$badgecheckdata2['levelid'];
           
           }else
           {
           $levelid=$badgecheckdata2['levelid'];
           $arrayset=array();
           $arrayset['userid']=$userid;
           $arrayset['badid']=0;
           $arrayset['levelid']=$checklevel['levelid'];
           $arrayset['level']=0;
           $arrayset['exp']=0;
           $arrayset['gxcid']=$gxcid;
           $arrayset['updatedate']=date("Y-m-d H:i:s");
           $arrayset['createdate']=date("Y-m-d H:i:s");
           $this->db->db_set($arrayset,'tb_game_activity');
           
           }
           
           
           }
           
           
           
           $arrayset=array();
           $sql='select * from tb_game_score where userid='.$userid;
           $gamescore=$this->db->db_set_1recordrow($sql);
           
           
           
           $sql='select sum(exp) as sumexppoint from tb_game_point where userid='.$userid;
           $sumpoint=$this->db->db_set_1recordrow($sql);
           $point=0;
           if($setting['point']=='0'||intval($expdata['sumexp'])==0)
           {
           
           }else
           {
           if($sumpoint['sumexppoint'])
           {
           
           }else
           {
           
           $sumpoint['sumexppoint']=0;
           
           }
           if(intval($setting['point'])>intval($expdata['sumexp']))
           {
           
           }else
           {
           if(intval($sumpoint['sumexppoint'])==0)
           {
           $point=intval(intval($expdata['sumexp'])/intval($setting['point']));
           $mod=intval($expdata['sumexp'])%intval($setting['point']);
         
           $point2=intval($expdata['sumexp'])-$mod;
           $arrayset=array();
           $arrayset['exp']=$point2;
           $arrayset['userid']=$userid;
           
           $this->db->db_set($arrayset,'tb_game_point');
           
           
           }else
           {
           
           if(intval($expdata['sumexp'])>intval($sumpoint['sumexppoint']))
           {
           
           $nowpoint=intval($expdata['sumexp'])-intval($sumpoint['sumexppoint']);
           
           if(intval($setting['point'])>$nowpoint)
           {
           
           }else
           {
           
           
           $point=intval($nowpoint/intval($setting['point']));
           $mod=intval($nowpoint)%intval($setting['point']);
           
           
           $point2=$nowpoint-$mod;
           $arrayset=array();
           $arrayset['exp']=$point2;
           $arrayset['userid']=$userid;
           
           $this->db->db_set($arrayset,'tb_game_point');
          
           }
           
           
           }
           
           
           }
           }
           
           }
           
           
           $arrayset=array();
           $arrayset['level']=0;
           $arrayset['exp']=intval($expdata['sumexp']);
           $arrayset['levelid']=$levelid;
           
           $arrayset['updatedate']=date("Y-m-d H:i:s");
           
           if($gamescore['gscoid'])
           {
           $arrayset['point']=intval($gamescore['point'])+intval($point);
           $this->db->db_set($arrayset,'tb_game_score',' gscoid='.$gamescore['gscoid']);
           
           }
           else
           {
           $arrayset['point']=$point;
           $arrayset['userid']=$userid;
           $arrayset['createdate']=date("Y-m-d H:i:s");
           $this->db->db_set($arrayset,'tb_game_score');
           }
           
           
           
           $sql="select sum(badge) as sumbadge from tb_game_log where userid=".$userid.' and gxcid='.$gxcid;
           $badgedata=$this->db->db_set_1recordrow($sql);
           $sumbadge=0;
           if($badgedata['sumbadge'])
           {
           $sumbadge=intval($badgedata['sumbadge']);
           
           }
           
           if($sumbadge>0)
           {
           
           $sql='select * from tb_game_badge where gxcid='.$gxcid.' and tb_game_badge.count<='.$sumbadge.' and tb_game_badge.count!=0';
           $badgecheckdata=$this->db->db_set_recordset($sql);
           if(count($badgecheckdata))
           {
           foreach($badgecheckdata as $valuecheck)
           {
           
           $sql='select * from tb_game_activity where tb_game_activity.badid='.$valuecheck['badid'].' and gxcid='.$gxcid.' and userid='.$userid;
           $badgecheckdata2=$this->db->db_set_1recordrow($sql);
           if($badgecheckdata2['glogid'])
           {
           
           
           }else
           {
           
           $arrayset=array();
           $arrayset['userid']=$userid;
           $arrayset['badid']=$valuecheck['badid'];
           $arrayset['levelid']=0;
           $arrayset['level']=0;
           $arrayset['exp']=0;
           $arrayset['gxcid']=$gxcid;
           $arrayset['updatedate']=date("Y-m-d H:i:s");
           $arrayset['createdate']=date("Y-m-d H:i:s");
           $this->db->db_set($arrayset,'tb_game_activity');
           
           }
           
           
           }
           }
           
           }
           
           
           
           
           
           
           }
           
           
           }
           
           
           
           }
           
           
           
           }
           
           
           
           }
           
           
           
           function getallgamnification()
           {
           $arraydata=array();
            $sql='select *
            ,(select tb_img.path from tb_img where tb_img.imgmid=tb_game_exp_setting.rimgmid) as pathimg
            ,(select tb_img.path from tb_img where tb_img.imgmid=tb_game_exp_setting.rimgsmid) as pathsimg
            
             from tb_game_exp_setting';
            $arraygexp=$this->db->db_set_1recordrow($sql);
            
            $arraydata['data']['exp']=$arraygexp;
            
            $sql='select *,(select tb_img.path from tb_img where tb_img.imgmid=tb_game_level.imgmid) as pathimg,(select tb_img.path from tb_img where tb_img.imgmid=tb_game_level.simgmid) as pathsimg
FROM
tb_game_level
order by tb_game_level.exp asc';
            $arraygexplv=$this->db->db_set_recordset($sql);
            $arraydata['data']['explevel']=$arraygexplv;
            
            $sql='SELECT
*
,(select tb_img.path from tb_img where tb_img.imgmid=tb_game_badge.dimgmid) as dimg
,(select tb_img.path from tb_img where tb_img.imgmid=tb_game_badge.dsimgmid) as dsimg
,(select tb_img.path from tb_img where tb_img.imgmid=tb_game_badge.aimgmid) as aimg
,(select tb_img.path from tb_img where tb_img.imgmid=tb_game_badge.aimgsmid) as asimg
FROM
tb_game_badge
order by tb_game_badge.count asc';

            $arraybadge=$this->db->db_set_recordset($sql);
            
            $arraydata['data']['badge']=$arraybadge;
            
            $sql='SELECT * FROM `tb_game_exp_config` order by tb_game_exp_config.gxcid asc ';
            
            $arrayexpconfig=$this->db->db_set_recordset($sql);
            
            $arraydata['data']['expconfig']=$arrayexpconfig;
            
           
            
            
            
            return $arraydata;
           
           }
           function getmygamnification($userid)
           {
           $sql='select * from tb_game_score where userid='.$userid;
           $mygam=$this->db->db_set_1recordrow($sql);
           $arraydata=array();
           if($mygam['gscoid'])
           {
           
           $arraydata['img']=baseinfo.'/imglevel/lv/lv001.png';
           $arraydata['simg']=baseinfo.'/imglevel/lv/lv001.png';
           
           if($mygam['level']=='0')
           {
           $mygam['level']=1;
           }
           
           $arraydata['name']='Level '.$mygam['level'];
           $arraydata['level']=$mygam['level'];
           $arraydata['exp']=number_format($mygam['exp']).' EXP';
           $arraydata['point']=$mygam['point'].' Points';
           $arraydata['shownow']='Next Level';
           
           
           $sql='SELECT
a.scoreexp,a.ranks,b.userid
FROM


( SELECT    scoreexp, @rank:=@rank+1 ranks
          FROM 

(SELECT
DISTINCT  (IF (tb_game_score.exp is NULL,0,tb_game_score.exp) ) as scoreexp
FROM
tb_user
LEFT JOIN tb_game_score ON tb_user.userid = tb_game_score.userid
ORDER BY scoreexp desc) t , (SELECT @rank:= 0) r ) a 

INNER JOIN  
(

SELECT
tb_user.userid,IF (tb_game_score.exp is NULL,0,tb_game_score.exp) as scoreexp
FROM
tb_user
LEFT JOIN tb_game_score ON tb_user.userid = tb_game_score.userid

) b ON a.scoreexp = b.scoreexp
where b.userid='.$userid;

$mygam2=$this->db->db_set_1recordrow($sql);

$arraydata['ranks']=$mygam2['ranks'];
           
           if($mygam['levelid']!='0')
           {
           $sql='select *,
           (select tb_img.path from tb_img where tb_img.imgmid=tb_game_level.simgmid) as dsimg,
           (select tb_img.path from tb_img where tb_img.imgmid=tb_game_level.imgmid) as dimg
            from tb_game_level where levelid='.$mygam['levelid'];
           $mygam2=$this->db->db_set_1recordrow($sql);
           $arraydata['name']=$mygam2['name'];
           if($mygam2['levelid'])
           {
           
           $arraydata['img']=baseinfo.'/'.$mygam2['dimg'];
           $arraydata['simg']=baseinfo.'/'.$mygam2['dsimg'];
           
           }
           $arraydata['shownow']=$arraydata['name'];
           
           }
       
           
           $sql="select * from tb_game_exp_setting";
           
           $expsetting=$this->db->db_set_1recordrow($sql);
           $arraydata['nextlevel']='N/A EXP';
           $arraydata['percent']='0%';
           if($expsetting['status']=='1')
           {
           
           $countlevel=intval(intval($mygam['exp'])/intval($expsetting['exp']));
            $arraydata['nextlevel']=number_format(intval($expsetting['exp'])*($countlevel+1)).' EXP';
            $arraydata['percent']=intval((100*$mygam['exp'])/(intval($expsetting['exp'])*($countlevel+1))).'%';
            
            $arraydata['shownow']='Next Level '.($countlevel+1);
            $textrow=sprintf("%03d",$countlevel );
           $arraydata['img']=baseinfo.'/imglevel/lv/lv'.$textrow.'.png';
           $arraydata['simg']=baseinfo.'/imglevel/lv/lv'.$textrow.'.png';
           
           }else if($expsetting['status']=='2')
           {
           
           $sql='select * from tb_game_level where tb_game_level.exp>'.$mygam['exp'].' order by tb_game_level.exp asc  limit 0,1';
           $gamelv=$this->db->db_set_1recordrow($sql);
           
           if($gamelv['levelid'])
           {
           $arraydata['shownow']='Next '.$gamelv['name'];
           $arraydata['percent']=intval((100*$mygam['exp'])/(intval($gamelv['exp']))).'%';
           $arraydata['nextlevel']=number_format(intval($gamelv['exp'])).' EXP';
           }else
           {
           $arraydata['percent']='0%';
           $arraydata['nextlevel']='N/A EXP';
           
           
           }
           
           
           
           }
           
           
           
           
           }else
           {
           $arraydata['img']=baseinfo.'/imglevel/lv/lv001.png';
           $arraydata['simg']=baseinfo.'/imglevel/lv/lv001.png';
           $arraydata['name']='Level 1';
           $arraydata['exp']='0 EXP';
           $arraydata['point']='0 Points';
           $arraydata['shownow']='Next Level';
           
           $sql="select * from tb_game_exp_setting";
           $arraydata['percent']='0%';
           $expsetting=$this->db->db_set_1recordrow($sql);
           $arraydata['nextlevel']='N/A EXP';
           if($expsetting['status']=='1')
           {
           $arraydata['shownow']='Next Level 1';
           $arraydata['nextlevel']=number_format(intval($expsetting['exp'])).' EXP';;
           
           }else if($expsetting['status']=='2')
           {
           
           $sql='select * from tb_game_level where tb_game_level.exp>0 order by tb_game_level.exp asc  limit 0,1';
           $gamelv=$this->db->db_set_1recordrow($sql);
           
            if($gamelv['levelid'])
           {
           $arraydata['shownow']='Next Level '.$gamelv['name'];
           $arraydata['nextlevel']=number_format(intval($gamelv['exp'])).' EXP';
           }else
           {
           $arraydata['nextlevel']='N/A EXP';
           
           }
           
           
           }
           
           
           }
           return $arraydata;
           
           }
           function getbadgealldata($userid)
           {
           $sql='select *,(select tb_img.path from tb_img where tb_img.imgmid=tb_game_badge.dimgmid) as dimg
,(select tb_img.path from tb_img where tb_img.imgmid=tb_game_badge.dsimgmid) as dsimg
,(select tb_img.path from tb_img where tb_img.imgmid=tb_game_badge.aimgmid) as aimg
,(select tb_img.path from tb_img where tb_img.imgmid=tb_game_badge.aimgsmid) as asimg
 from tb_game_badge';
            $arrayexpconfig=$this->db->db_set_recordset($sql);
            $arraydata=array();
            if(count($arrayexpconfig))
            {$k=0;
            foreach($arrayexpconfig as $valueconfig)
            {
            
            $sql='select glogid from tb_game_activity where badid='.$valueconfig['badid'].' and userid='.$userid;
            $arraycheck=$this->db->db_set_1recordrow($sql);
            $arraydata[$k]['name']=$valueconfig['bname'];
            $arraydata[$k]['desc']=$valueconfig['bdesc'];
            if($arraycheck['glogid'])
            {
            $arraydata[$k]['img']=baseinfo.'/'.$valueconfig['asimg'];
            }else
            {
            
            $arraydata[$k]['img']=baseinfo.'/'.$valueconfig['dsimg'];
            }
            $k++;
            }
            
            }
           return $arraydata;
           
           }
           function getruledata()
           {
           $sql='select IF (tb_game_exp_setting.rimgsmid = 0, \'img/game.jpg\',(select tb_img.path from tb_img where tb_img.imgmid=tb_game_exp_setting.rimgsmid) ) as imgpath from tb_game_exp_setting';
            $mygam2=$this->db->db_set_1recordrow($sql);
            return $mygam2['imgpath'];
           
           
           }
           function getscoreleaderborad($userid)
           {
           
           
           $sql='SELECT
tb_game_score.userid,
tb_game_score.level,
tb_game_score.levelid,
tb_user.username,
IF (tb_user.displayname = \'\', tb_user.username,tb_user.displayname) as displayname,
IF (tb_user.simgmid = 0, \'img/dfthmbuser.jpg\',(select tb_img.path from tb_img where tb_img.imgmid=tb_user.simgmid) ) as imgpath
FROM
tb_game_score
INNER JOIN tb_user ON tb_game_score.userid = tb_user.userid
order by tb_game_score.exp desc 
limit 0,10';
            $arraydata=$this->db->db_set_recordset($sql);
            ;
            $arraynewdata=array();
            if(count($arraydata))
            {
            $k=0;
            foreach($arraydata as $valuedata)
            {
            if($valuedata['level']=='0')
            {
            $valuedata['level']=1;
            }
            $arraydata[$k]['name']='Level '.$valuedata['level'];
            if($valuedata['levelid']!='0')
            {
            $sql='select tb_game_level.name
            from tb_game_level where levelid='.$valuedata['levelid'];
            $mygam2=$this->db->db_set_1recordrow($sql);
           $arraydata[$k]['name']=$mygam2['name'];
            
            }  
            
            $k++;
            
            }
            
            }
            
             $arraynewdata['all']=$arraydata;
           
           
           $sql='SELECT
tb_game_score.userid,
tb_game_score.level,
tb_game_score.levelid,
tb_user.username,
IF (tb_user.displayname = \'\', tb_user.username,tb_user.displayname) as displayname,
IF (tb_user.simgmid = 0, \'img/dfthmbuser.jpg\',(select tb_img.path from tb_img where tb_img.imgmid=tb_user.simgmid) ) as imgpath
FROM
tb_game_score
INNER JOIN tb_user ON tb_game_score.userid = tb_user.userid
INNER JOIN tb_follow ON tb_follow.userid = tb_game_score.userid
where tb_follow.createby='.$userid;
            
            $arraydata=$this->db->db_set_recordset($sql);
            
            
            if(count($arraydata))
            {
            $k=0;
            foreach($arraydata as $valuedata)
            {
             if($valuedata['level']=='0')
            {
            $valuedata['level']=1;
            }
            $arraydata[$k]['name']='Level '.$valuedata['level'];
            if($valuedata['levelid']!='0')
            {
            $sql='select tb_game_level.name
            from tb_game_level where levelid='.$valuedata['levelid'];
            $mygam2=$this->db->db_set_1recordrow($sql);
           $arraydata[$k]['name']=$mygam2['name'];
            
            }  
            
            $k++;
            
            }
            
            }
            
             $arraynewdata['following']=$arraydata;
             
             
             
             
             $sql='SELECT
tb_game_score.userid,
tb_game_score.level,
tb_game_score.levelid,
tb_user.username,
IF (tb_user.displayname = \'\', tb_user.username,tb_user.displayname) as displayname,
IF (tb_user.simgmid = 0, \'img/dfthmbuser.jpg\',(select tb_img.path from tb_img where tb_img.imgmid=tb_user.simgmid) ) as imgpath
FROM
tb_game_score
INNER JOIN tb_user ON tb_game_score.userid = tb_user.userid
INNER JOIN tb_follow ON tb_follow.createby = tb_game_score.userid
where tb_follow.userid='.$userid;
            
            $arraydata=$this->db->db_set_recordset($sql);
            
            
            if(count($arraydata))
            {
            $k=0;
            foreach($arraydata as $valuedata)
            {
             if($valuedata['level']=='0')
            {
            $valuedata['level']=1;
            }
            $arraydata[$k]['name']='Level '.$valuedata['level'];
            if($valuedata['levelid']!='0')
            {
            $sql='select tb_game_level.name
            from tb_game_level where levelid='.$valuedata['levelid'];
            $mygam2=$this->db->db_set_1recordrow($sql);
           $arraydata[$k]['name']=$mygam2['name'];
            
            }  
            
            $k++;
            
            }
            
            }
            
             $arraynewdata['follower']=$arraydata;
             
             return $arraynewdata;
           
           
           
           }
           
           
           function getgameuserlist($page,$searchtext=''){
           $page=(($page-1)*12);
           $where='';
            if($searchtext)
            {
            $where=' where tb_user.displayname like "%'.$searchtext.'%" or tb_user.username like "%'.$searchtext.'%"';
            }
            $sql='SELECT
tb_game_score.gscoid,
IF (tb_user.displayname = \'\', tb_user.username,tb_user.displayname) as displayname,
IF (tb_user.simgmid = 0, \'img/dfthmbuser.jpg\',(select tb_img.path from tb_img where tb_img.imgmid=tb_user.simgmid) ) as imgpath,
tb_user.simgmid,
tb_user.username,
tb_game_score.userid,
tb_game_score.`level`,
tb_game_score.exp,
tb_game_score.point,
tb_game_score.levelid,
tb_game_score.updatedate,
tb_game_score.createdate
FROM
tb_game_score
INNER JOIN tb_user ON  tb_user.userid = tb_game_score.userid
'.$where.'
limit '.$page.',12';
            
            $arrayuserlist=$this->db->db_set_recordset($sql);
            if(count($arrayuserlist))
            {
            $k=0;
            foreach($arrayuserlist as $valueuserlist)
            {
            $arrayuserlist[$k]['levelset']=array();
            if($valueuserlist['levelid']!='0')
            {
            $sql='select * from tb_game_level where levelid='.$valueuserlist['levelid'];

            $levelrowset=$this->db->db_set_1recordrow($sql);
            $arrayuserlist[$k]['levelset']=$levelrowset;
            }
            $k++;
            
            }
            }
            $arraydata['data']=$arrayuserlist;
            $sql='SELECT count(tb_game_score.gscoid) as countgame from tb_game_score INNER JOIN tb_user ON  tb_user.userid = tb_game_score.userid '.$where;
            $arraygame=$this->db->db_set_1recordrow($sql);
            $arraydata['page']=intval($arraygame['countgame']);
            
            return $arraydata;
            
            
            
           
           }
           
           function getimagebyimgmid($imgmid="",$defalutimg="",$width="",$height="",$select="")
           {
           
             
           
             $sql="select path,width,height,imgmid $select from tb_img where imgmid='".$imgmid."'";
             $arraydata=$this->db->db_set_1recordrow($sql);
             if($arraydata['path'])
             {
                 
                 if(intval($arraydata['width'])==0)
                 {
                 $arraydata['newpath']=baseinfo.'/img/dfthmbcell.jpg';
                 $arraydata['width']= 600;
                 $arraydata['height']=600;
                 
                 }else
                 {
                 $arraydata['newpath']=baseinfo.'/'.$arraydata['path'];
                 $arraydata['width']= intval($arraydata['width']);
                 $arraydata['height']=intval($arraydata['height']);
                 
                 }
                 
             
             
             }else
             {
                if($defalutimg)
                {
                $arraydata['newpath']=$defalutimg;
                $arraydata['width']=intval($width);
                $arraydata['height']=intval($height);
                }else
                {
                $arraydata['newpath']=baseinfo.'/img/dfthmbuser.jpg';
                $arraydata['width']=350;
                $arraydata['height']=350;
                
                }
             
             
             }
             return $arraydata;
           
           
           }
           
           function saveimagedata($dataArray=array())
           {
           if(count($dataArray))
           {
           if(!$dataArray['updatedate'])
           {
           $dataArray['updatedate']=date("Y-m-d H:i:s");
           $dataArray['updateby']=$this->userdata['userid'];
           }
           
           
           if($dataArray['imgmid'])
           {
           $imgmid=$dataArray['imgmid'];
           unset($dataArray['imgmid']);
           if(!$dataArray['imgid'])
           {
           $sql="SELECT imgid,imgname  FROM tb_img where imgmid=".$imgmid;
           $arrayimage=$this->db->db_set_1recordrow($sql);
           $dataArray['imgid']=$arrayimage['imgid'];
           $dataArray['imgname']=$arrayimage['imgname'];
           
           $this->db->db_set($dataArray,"tb_img");
           $imgmid=$this->db->db_get_last_number();
           
           }else
           {
           $this->db->db_set($dataArray,"tb_img"," imgmid=".$imgmid);
           
           }
           
           
           
           
           
           return $imgmid;
           
           }else if($dataArray['imgid'])
           {
           
           $this->db->db_set($dataArray,"tb_img");
           $imgmid=$this->db->db_get_last_number();
           return $imgmid;
           
           }else
           {
           
           $sql="SELECT MAX(imgid) as maximgid FROM tb_img";
           $arrayimage=$this->db->db_set_recordset($sql);
           $dataArray['imgid']=$arrayimage[0]['maximgid']+1;
           $this->db->db_set($dataArray,"tb_img");
           $imgmid=$this->db->db_get_last_number();
           return $imgmid;
           
           }
           }
           
           }
           function getnotificationlistbyuserid($userid='',$page=1,$fiter=0,$nottid=0,$date=0)
           {
           $page=(($page-1)*12);
           if($nottid)
           {
           $sql=" select * from tb_notification where nottid=$nottid ";   
           }else
           {
           if($userid)
           {
           if($fiter==1)
           {
           
           $sql="
                    select * from (
                    select * from 
                    (
                    select * from tb_notification   where conid=35 and userid=".$userid." 
                    UNION ALL
                    select * from tb_notification   where conid=2 and userid=".$userid." 
                    ) tb_notification ORDER BY createdate desc 
                    ) tb_notification GROUP BY createby
                    order by tb_notification.createdate desc
                    limit $page,12
                    ";
           
           
           }
           else if($fiter==3)
           {
           
           $sql=" select * from tb_notification where notifyid<>0 and userid=0 order by tb_notification.createdate desc";
           
           }
           else
           {
           
           if($date)
           {
           $limit='';
           $where=' where tb_notification.createdate   between date_sub(now(),INTERVAL 1 WEEK) and now()';
           
           }else
           {
           $where='';
           $limit="limit $page,12";
           }
           
           $sql="
                    select * from (
                    
                    
                    select * from tb_notification where (msgid=0 and notifyid=0 and  userid=".$userid.")  
                    UNION ALL

                    select * from (
                    select * from 
                    (
                    select * from tb_notification   where conid=35 and userid=".$userid." 
                    UNION ALL
                    select * from tb_notification   where conid=2 and userid=".$userid." 
                    ) tb_notification ORDER BY createdate desc 
                    ) tb_notification GROUP BY createby

                    ) tb_notification
                    $where
                    order by tb_notification.createdate desc
                    $limit

           ";
           
           }
           
           }else
           {
           
           $sql=" select * from tb_notification where   notifyid<>0 and userid=0 order by tb_notification.createdate desc  limit $page,12";
           
           
           }
           }
           //echo $sql;
           $arraydata=$this->db->db_set_recordset($sql);
           $arraynewdata=array();
           if(count($arraydata))
           {
           
           foreach($arraydata as $valuedata)
           {
           $valuedata['read']=intval($valuedata['read']);
           $namecondition=$this->getconditionmsgbyid($valuedata['conid']);
           if($valuedata['msgid'])
           {
             $sql="select * from tb_msg where tb_msg.msgid=".$valuedata['msgid'];
             $datamsg=$this->db->db_set_1recordrow($sql);
            
            
            $datauser=$this->getuserbyuserid($datamsg['userid']);
            $datamyuser=$this->getuserbyuserid($datamsg['createby']);
             
            $datauser['imguser']=$this->getimagebyimgmid($datauser['imgmid']);
            $datauser['simguser']=$this->getimagebyimgmid($datauser['simgmid']);
            
            $datamyuser['imguser']=$this->getimagebyimgmid($datamyuser['imgmid']);
            $datamyuser['simguser']=$this->getimagebyimgmid($datamyuser['simgmid']);
             

            $datamsg['notiid']=$valuedata['notiid'];
            $datamsg['createdate']=$valuedata['createdate'];
            
            $datamsg['fromuser']=$datamyuser;
            
            $datamsg['touser']=$datauser;
            
            $datamsg['read']=$valuedata['read'];
            
            $datamsg['type']=0;
            
            $datamsg['conid']=$valuedata['conid'];
            
            $datamsg['newdate']=date("d/m/Y",strtotime($datamsg['createdate'])) ;
            $datamsg['newdateid']=date("d-m-Y",strtotime($datamsg['createdate'])) ;
            $datamsg['newtime']=date("g:i a",strtotime($datamsg['createdate'])) ;
            
            $datamsg['ismsg']=0; 
            
            $datamsg['imgarr']=array();
            if($datamsg['imgmid'])
            {
            
            $datamsg['imgarr']=$this->getimagebyimgmid($datamsg['imgmid']);
            
            }
            
             if($datamyuser['userid']==$this->userdata['userid'])
            {
            $userid=$datauser['userid'];
            }else
            {
            $userid=$datamyuser['userid'];
            
            }
            
            if($valuedata['conid']==35)
            {
            $displayname=$datauser['displayname'];
           
            
            $datamsg['linkto']=baseinfo.'/'.$this->userdata['username'].'/messages?userid='.$userid;
            
            }else
            {
            $displayname=$datamyuser['displayname'];
            $datamsg['linkto']=baseinfo.'/'.$this->userdata['username'].'/messages?userid='.$userid;
            
            }
            $datamsg['msg']=stripslashes($datamsg['msg']);
            $datamsg['condition']=$namecondition;
            $datamsg['msgshow']=stripslashes($displayname.' '.$namecondition.' '.$datamsg['msg']);
             $arraynewdata[]=$datamsg;
             
           }
           else if($valuedata['bid'])
           {
           $sql="select * from tb_boardcasting where tb_boardcasting.bid=".$valuedata['bid'];
           $databroading=$this->db->db_set_1recordrow($sql);
           $datamyuser=$this->getuserbyuserid($databroading['createby']);
           $datamyuser['imguser']=$this->getimagebyimgmid($datamyuser['imgmid']);
           $datamyuser['simguser']=$this->getimagebyimgmid($datamyuser['simgmid']);
           $databroading['fromuser']=$datamyuser;
           $databroading['condition']=$namecondition;
           $databroading['read']=$valuedata['read'];
           $databroading['notiid']=$valuedata['notiid'];
           $databroading['conid']=$valuedata['conid'];
           
           
           $databroading['createdate']=$valuedata['createdate'];
           $msgto=$databroading['msg'];
           $type=0;
           $databroading['productid']=0;
           if($databroading['link'])
           {
           $msgto=$databroading['link'];
           $type=1;
           if(strpos($msgto,baseinfo)===true)
           {
           $arraymsgto=explode("/",$msgto);
           $productid=$arraymsgto[count($arraymsgto)-1];
           
           if(is_numeric($productid))
           {
           $databroading['productid']=intval($productid);
           $type=2;
           }
           
           }
           $databroading['linkto']=$databroading['link'];
           
           }else
           {
             $databroading['ismsg']=1;
           }
           $databroading['type']=$type;
           
           $databroading['msgshow']=stripslashes($datamyuser['displayname'].' '.$namecondition.' '.$msgto);
           $arraynewdata[]=$databroading;
           
           }
           else if($valuedata['notifyid'])
           {
           $sql="select * from tb_notify where tb_notify.notifyid=".$valuedata['notifyid'];
           $databroading=$this->db->db_set_1recordrow($sql);
           $datamyuser=$this->getuserbyuserid($databroading['createby']);
           $datamyuser['imguser']=$this->getimagebyimgmid($datamyuser['imgmid']);
           $datamyuser['simguser']=$this->getimagebyimgmid($datamyuser['simgmid']);
           $databroading['fromuser']=$datamyuser;
           $databroading['condition']=$namecondition;
           $databroading['notiid']=$valuedata['notiid'];
           $databroading['createdate']=$valuedata['createdate'];
           $databroading['linkto']=baseinfo.'/'.$datamyuser['username'];
           $databroading['conid']=$valuedata['conid'];  
           if($this->userdata['userid'])
           {
           $bcheck=$this->checkreadnotify($this->userdata['userid'],$valuedata['notifyid']);
           if($bcheck)
           {
           $readnoti=1;
           }else
           {
           $readnoti=0;
           }
           
           $databroading['read']=$readnoti;
           
           }else
           {
           $databroading['read']=0;
           }
           
           
           $msgto=$databroading['msg'];
           $type=0;
           $databroading['productid']=0;
           $databroading['ismsg']=0; 
           if($databroading['link'])
           {
           $msgto=$databroading['link'];
           $type=1;
             if(strpos($msgto,baseinfo)===true)
           {
           $arraymsgto=explode("/",$msgto);
           $productid=$arraymsgto[count($arraymsgto)-1];
           
           if(is_numeric($productid))
           {
           $databroading['productid']=intval($productid);
           $type=2;
           }
           
           }
           }
           else
           {
             $databroading['ismsg']=1;
           }
           $databroading['type']=$type;
           $databroading['msgshow']=stripslashes($datamyuser['displayname'].' '.$namecondition.' '.$msgto);
           $arraynewdata[]=$databroading;
           
           }
           else if($valuedata['foid'])
           {
           
           $sql="select * from tb_follow where tb_follow.foid=".$valuedata['foid'];
           $datafollow=$this->db->db_set_1recordrow($sql);
           $datamyuser=$this->getuserbyuserid($datafollow['createby']);
           $datamyuser['imguser']=$this->getimagebyimgmid($datamyuser['imgmid']);
           $datamyuser['simguser']=$this->getimagebyimgmid($datamyuser['simgmid']);
           $datafollow['fromuser']=$datamyuser;
           $datafollow['read']=$valuedata['read'];
           $datafollow['ismsg']=0; 
           $datafollow['conid']=$valuedata['conid'];  
           if($valuedata['conid']==37)
           {
           $setto="requests";
           }else
           {
           $setto="followers";
           }
           
           $datafollow['linkto']=baseinfo.'/'.$this->userdata['username'].'/'.$setto;
           
           $datafollow['condition']=$namecondition;
           $datafollow['createdate']=$valuedata['createdate'];
           $datafollow['notiid']=$valuedata['notiid'];
           $datafollow['type']=4;
           
           $datafollow['msgshow']=stripslashes($datamyuser['displayname'].' '.$namecondition);
           $arraynewdata[]=$datafollow;
           
           }
           else if($valuedata['lid'])
           {
           $sql="select tb_like.createby,tb_product.productid,tb_product.title,tb_product.link from tb_like inner join tb_product on tb_like.productid = tb_product.productid  where tb_like.lid=".$valuedata['lid'];
           $datalike=$this->db->db_set_1recordrow($sql);
           $datamyuser=$this->getuserbyuserid($datalike['createby']);
           $datamyuser['imguser']=$this->getimagebyimgmid($datamyuser['imgmid']);
           $datamyuser['simguser']=$this->getimagebyimgmid($datamyuser['simgmid']);
           $datalike['fromuser']=$datamyuser;
           $datalike['condition']=$namecondition;
           $datalike['read']=$valuedata['read'];
           $datalike['notiid']=$valuedata['notiid'];
           $datalike['conid']=$valuedata['conid'];  
           
           
           
           $datalike['createdate']=$valuedata['createdate'];

           $type=2;
           
          
           $msgto=$datalike['title'];
           
          //$datalike['link']=$msgto;
           $datalike['linkto']=baseinfo.'/'.$datalike['link'].'/'.$datalike['productid'];
           $datalike['type']=$type;
            $datalike['msg']=$msgto;  
           
           
           $datalike['msgshow']=stripslashes($datamyuser['displayname'].' '.$namecondition.' '.$msgto);
           $arraynewdata[]=$datalike;
           
           }
           else if($valuedata['pointid'])
           {
           $sql="SELECT
tb_product.title,tb_product.productid,tb_product.link
FROM
tb_product
INNER JOIN tb_product_point ON tb_product.productid = tb_product_point.productid
 where tb_product_point.productid=".$valuedata['pointid'];
           $datalike=$this->db->db_set_1recordrow($sql);
           $datamyuser=$this->getuserbyuserid($valuedata['createby']);
           $datamyuser['imguser']=$this->getimagebyimgmid($datamyuser['imgmid']);
           $datamyuser['simguser']=$this->getimagebyimgmid($datamyuser['simgmid']);
           $datalike['fromuser']=$datamyuser;
           $datalike['condition']=$namecondition;
           $datalike['read']=$valuedata['read'];
           $datalike['notiid']=$valuedata['notiid'];
           $datalike['conid']=$valuedata['conid']; 
           
           
           
           $datalike['createdate']=$valuedata['createdate'];

           $type=2;
           
          
           $msgto=$datalike['title'];
           
          //$datalike['link']=$msgto;
           $datalike['linkto']=baseinfo.'/'.$datalike['link'].'/'.$datalike['productid'];
           $datalike['type']=$type;
            $datalike['msg']=$msgto;  
           
           
           $datalike['msgshow']=stripslashes($datamyuser['displayname'].' '.$namecondition.' '.$msgto);
           $arraynewdata[]=$datalike;
           
           }
           else if($valuedata['favid'])
           {
           $sql="select tb_fav.createby,tb_product.productid,tb_product.title,tb_product.link from tb_fav inner join tb_product on tb_fav.productid = tb_product.productid  where tb_fav.favid=".$valuedata['favid'];
           $datalike=$this->db->db_set_1recordrow($sql);
           $datamyuser=$this->getuserbyuserid($datalike['createby']);
           $datamyuser['imguser']=$this->getimagebyimgmid($datamyuser['imgmid']);
           $datamyuser['simguser']=$this->getimagebyimgmid($datamyuser['simgmid']);
           $datalike['fromuser']=$datamyuser;
           $datalike['condition']=$namecondition;
           $datalike['read']=$valuedata['read'];
           $datalike['notiid']=$valuedata['notiid'];
           $datalike['conid']=$valuedata['conid']; 
           
           
           
           $datalike['createdate']=$valuedata['createdate'];

           $type=2;
           
          
           $msgto=$datalike['title'];
           
          //$datalike['link']=$msgto;
           $datalike['linkto']=baseinfo.'/'.$datalike['link'].'/'.$datalike['productid'];
           $datalike['type']=$type;
            $datalike['msg']=$msgto;  
           
           
           $datalike['msgshow']=stripslashes($datamyuser['displayname'].' '.$namecondition.' '.$msgto);
           $arraynewdata[]=$datalike;
           
           }
           else if($valuedata['comid'])
           {
           $sql="select * from tb_plugins_comment_value where tb_plugins_comment_value.comvid=".$valuedata['comid'];
           $datalike=$this->db->db_set_1recordrow($sql);
           $datamyuser=$this->getuserbyuserid($datalike['createby']);
           $datamyuser['imguser']=$this->getimagebyimgmid($datamyuser['imgmid']);
           $datamyuser['simguser']=$this->getimagebyimgmid($datamyuser['simgmid']);
           $datalike['fromuser']=$datamyuser;
           $datalike['condition']=$namecondition;
           $datalike['read']=$valuedata['read'];
           $datalike['notiid']=$valuedata['notiid'];
           $datalike['conid']=$valuedata['conid']; 
           
           
           
           $datalike['createdate']=$valuedata['createdate'];

           $type=2;
           
          
           $msgto=$datalike['msg'];
           
          //$datalike['link']=$msgto;
           $datalike['linkto']=baseinfo.'/post/'.$datalike['productid'];
           $datalike['type']=$type;
            $datalike['msg']=$msgto;  
           
           
           $datalike['msgshow']=stripslashes($datamyuser['displayname'].' '.$namecondition.' '.$msgto);
           $arraynewdata[]=$datalike;
           
           }
           else if($valuedata['smsgid'])
           {
           $sql='select * from tb_super_msg where smsgid='.$valuedata['smsgid'];
           $datamsg=$this->db->db_set_1recordrow($sql);
           
           
           $datamyuser=$this->getuserbyuserid($valuedata['createby']);
           $datamyuser['imguser']=$this->getimagebyimgmid($datamyuser['imgmid']);
           $datamyuser['simguser']=$this->getimagebyimgmid($datamyuser['simgmid']);
           $datamsg['fromuser']=$datamyuser;
           if($datamsg['orderid'])
           {
           $datamsg['condition']=$datamsg['msg'];
           unset($datamsg['msg']);
           
    
           }else
           {
           $datamsg['condition']=$namecondition;
           }
           
           
           $datamsg['read']=$valuedata['read'];
           $datamsg['notiid']=$valuedata['notiid'];
           $datamsg['conid']=$valuedata['conid']; 
           
           


           $type=2;
           
          
           
           
          //$datalike['link']=$msgto;
           if($datamsg['productid'])
           {
           $datamsg['linkto']=baseinfo.'/post/'.$datamsg['productid'];
           }else if($datamsg['orderid']&&$datamsg['typeorder']=='1')
           {
           $datamsg['linkto']=baseinfo.'/cart?orderid='.$datamsg['orderid'];
           
           }else if($datamsg['orderid']&&$datamsg['typeorder']=='2')
           {
           $datamsg['linkto']=baseinfo.'/cartmanage?orderid='.$datamsg['orderid'];
           
           }
           
           $datamsg['type']=$type;

           
           
           $datamsg['msgshow']=stripslashes($msgto);
           $arraynewdata[]=$datamsg;
           
           }
           
           }
           
           }
           return $arraynewdata;
           
           
           
           }
           function countnotificationlistbyuserid($userid='',$fiter=0,$read=0)
           {
            if($userid)
           {
           if($fiter==1)
           {
           
           $sql="
                    select count(*) as countdata from (
                    select * from 
                    (
                    select * from tb_notification   where conid=35 and userid=".$userid." 
                    UNION ALL
                    select * from tb_notification   where conid=2 and userid=".$userid." 
                    ) tb_notification ORDER BY createdate desc 
                    ) tb_notification GROUP BY createby
                    where tb_notification.read=".$read."
                    
                    ";
           
           
           }else if($fiter==3)
           {
           
           $string="IS NULL";
           if($read)
           {
           $string="IS NOT NULL";  
           }
           
           $sql=" SELECT
                    count(*) as countdata
                    FROM
                    tb_notification
                     LEFT JOIN tb_read_notify  ON tb_notification.notifyid = tb_read_notify.notifyid
                     where tb_read_notify.readid $string and tb_read_notify.userid=".$userid." ";
           
           
           }
           
           else
           {
           $sql="
                    select count(*) as countdata from (
                    
                    
                    select * from tb_notification where (msgid=0 and notifyid=0 and  userid=".$userid.")  
                    UNION ALL

                    select * from (
                    select * from 
                    (
                    select * from tb_notification   where conid=35 and userid=".$userid." 
                    UNION ALL
                    select * from tb_notification   where conid=2 and userid=".$userid." 
                    ) tb_notification ORDER BY createdate desc 
                    ) tb_notification GROUP BY createby

                    ) tb_notification
                    where tb_notification.read=".$read."

           ";
           
           }
           
           }
           else
           {
           
           return 0;
           }
           
           $arraydata=$this->db->db_set_1recordrow($sql);
           return $arraydata['countdata'];
           
           }
           function checkreadnotify($userid,$notifyid)
           {
           $sql="select readid from tb_read_notify where userid=".$userid." and notifyid=".$notifyid;
           $arrayread=$this->db->db_set_1recordrow($sql);
           if($arrayread['readid'])
           {
            return true;
           }else
           {
           
           return false;
           }
           
           }
           function getuseralldata($oauth,$selectdata="")
           {
           
           
           $select=",address,firstname,lastname,bannerimgmid,sbannerimgmid,facebook,twitter,tb_user.code,googleplus,website,phone,fax,etc,publish,proid,disid,tumid,countryid,tb_user.state,tb_user.email,birthdate,gender,lat,lng,description ".$selectdata;
           
          $arraynewdata['userdata']=$this->getuserbyoauth($oauth,$select);
          $arraynewdata['userdata']['imguser']=$this->getimagebyimgmid($arraynewdata['userdata']['imgmid']);
          $arraynewdata['userdata']['simguser']=$this->getimagebyimgmid($arraynewdata['userdata']['simgmid']);
          
          
          
          
          $userid=$arraynewdata['userdata']['userid'];
          
          
          if (defined('canonalgologin'))
            {
            $sql="select * from tb_serial where createby='".$arraynewdata['userdata']['userid']."' and serial<>'' ";
            $arraycheck=$this->db->db_set_1recordrow($sql);
            
            
            $arraynewdata['userdata']['model']='';
            if($arraycheck['serial'])
            {
            
            $arraynewdata['userdata']['model']=$this->gotocheck($arraycheck['serial'],1);
            
            
            }
             if($userid)
         { 
            $arraynewdata['userdata']['serial']=$this->getserialbyuserid($userid);
         }
            }
            
            
            if($userid)
         { 
          $arraynewdata['userdata']['countproduct']=$this->countproduct($userid);
          $arraynewdata['userdata']['countlikeproduct']=$this->countlikeproduct($userid);
          $arraynewdata['userdata']['counttagproduct']=$this->counttagproduct($userid);
          
          $arraynewdata['userdata']['countfollower']=$this->countfollower($userid);
          $arraynewdata['userdata']['countfollowing']=$this->countfollowing($userid);
          $arraynewdata['userdata']['countrequest']=$this->countrequests($userid);
          $arraynewdata['userdata']['countblock']=$this->countblock($userid);
          
          $arraynewdata['userdata']['status']=intval($arraynewdata['userdata']['status']);
          $arraynewdata['userdata']['userid']=intval($arraynewdata['userdata']['userid']);
          $arraynewdata['userdata']['roleid']=intval($arraynewdata['userdata']['roleid']);
          $arraynewdata['userdata']['publish']=intval($arraynewdata['userdata']['publish']);
          $arraynewdata['userdata']['lat']=floatval($arraynewdata['userdata']['lat']);
          $arraynewdata['userdata']['lng']=floatval($arraynewdata['userdata']['lng']);
          $arraynewdata['userdata']['countproduct']=intval($arraynewdata['userdata']['countproduct']);
          $arraynewdata['userdata']['countlikeproduct']=intval($arraynewdata['userdata']['countlikeproduct']);
          $arraynewdata['userdata']['counttagproduct']=intval($arraynewdata['userdata']['counttagproduct']);
          $arraynewdata['userdata']['gendername']=$this->getgendername($arraynewdata['userdata']['gender']);
          $arraynewdata['userdata']['gender']=intval($arraynewdata['userdata']['gender']);
          

          
          unset($arraynewdata['userdata']['oauth']);
          
          
          
          $arraynewdata['userdata']['countryname']=$this->getcountrynamebycoutryid($arraynewdata['userdata']['countryid']);
          $arraynewdata['userdata']['statedata']=$arraynewdata['userdata']['state']; 
          if($arraynewdata['userdata']['countryid']==210)
          {
          if($arraynewdata['userdata']['proid'])
          {
          $arraynewdata['userdata']['state']=$this->getprovincebyproid($arraynewdata['userdata']['proid']);
          }
          
         
          
          if($arraynewdata['userdata']['disid'])
          {
             $where=array();
             $select="disname";
             $where['disid']=$arraynewdata['userdata']['disid'];
             $names=$this->getdatarow("tb_district",$select,$where,1);
             $arraynewdata['userdata']['disname']=$names['disname'];
          }
          
          if($arraynewdata['userdata']['tumid'])
          {
             $where=array();
             $select="tumname";
             $where['tumid']=$arraynewdata['userdata']['tumid'];
             $names=$this->getdatarow("tb_tumbon",$select,$where,1);
             $arraynewdata['userdata']['tumname']=$names['tumname'];
          }
          
          }else if($arraynewdata['userdata']['state'])
          {
          $arraynewdata['userdata']['state']=$arraynewdata['userdata']['state'];
          
          }
          
          unset(  $arraynewdata['userdata']['contryname']);
          
          
          
          
          $arraynewdata['userdata']['bannerimgarray']=$this->getimagebyimgmid($arraynewdata['userdata']['bannerimgmid'],baseinfo.'/img/cover1.jpg',960,300);
          $arraynewdata['userdata']['sbannerimgarray']=$this->getimagebyimgmid($arraynewdata['userdata']['sbannerimgmid'],baseinfo.'/img/cover1.jpg',960,300);
           }else
           {
            $arraynewdata['userdata']=array();
           
           }
          return $arraynewdata;
           
           }
           
           function gettitledataall()
           {
                $sql="SELECT
               info_title.title,
               info_title.tid,
               info_doc.docid,
               info_doc.title as titledoc,
               info_doc.path
                FROM
                info_title
                INNER JOIN info_doc ON info_title.tid = info_doc.tid";

                $arraydata=$this->db->db_set_recordset($sql);

                $arraynewdata=array();
                if(count($arraydata))
                {
                  $temptitle="";
                  $k=0;
                  foreach($arraydata as $valuedata)
                  {
                     if($valuedata['title']!=$temptitle)
                     {
                     
                       $temptitle=$valuedata['title'];
                       
                     
                     }
                     $arraynewdata[$temptitle][$k]['titledoc']=$valuedata['titledoc'];
                     $arraynewdata[$temptitle][$k]['docid']=$valuedata['docid'];
                     $arraynewdata[$temptitle][$k]['path']=$valuedata['path'];
                     $k++;
                  
                  
                  }
                
                }
                
                return $arraynewdata;
      
           }
           
           function countproduct($userid)
           {
           
           $sql="select count(productid) as countproduct from tb_product where tb_product.createby=".$userid." and tb_product.delete=0";
           $data=$this->db->db_set_1recordrow($sql);
           return $data['countproduct'];
           
           
           }
           
           function countlikeproduct($userid)
           {
           $sql="select count(lid) as countlikeproduct from  tb_like inner join tb_product on tb_product.productid=tb_like.productid  where tb_like.createby=".$userid." and tb_like.status=2 and tb_product.delete=0";
           $data=$this->db->db_set_1recordrow($sql);
           return $data['countlikeproduct'];
           
           
           }
           
           function counttagproduct($userid)
           {
           
        //   $sql="select count(tb_relate_tag.rtagid) as counttagproduct from tb_relate_tag inner join (select * from tb_product where tb_product.delete=0 and  tb_product.createby=".$userid." ) as tb_product on  tb_product.productid=tb_relate_tag.productid  ";
           
           

$sql="SELECT count(*) as counttagproduct from(
select count(*) counttag
from tb_relate_tag 
INNER join (select productid from tb_product where tb_product.`delete`=0 and tb_product.createby=".$userid.") tb_product on tb_product.productid=tb_relate_tag.productid
GROUP BY tagid) tb_product";


           $data=$this->db->db_set_1recordrow($sql);
           $row=0;
           if($data['counttagproduct'])
           {
           $row=$data['counttagproduct'];
           }
           return $row;
           
           
           }
           
           function getfeaturebyfid($fid,$all=0)
           {
           
             if(count($this->info['configall']['feature']))
             {
             foreach($this->info['configall']['feature'] as $valuefeature)
             {
               if($valuefeature['fid']==$fid)
               {
                 if($all==0)
                 {
                 unset($valuefeature['plugins']);
                 }
                 
                 return $valuefeature;
               
               }
             
             }
              
             }
           
           
           }
           
           function savephotobase64($base64)
           {
           $photo=mktime() .  '-' . rand(0, 10000) . '.jpg'; 

           //.'/'.$arrayimg['name'];
           $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
           $folder=cacheimgpath.'/user/'.$arrayuser['userid'];
           
            if(!is_dir(cacheimgpath.'/user/'.$arrayuser['userid']))
                     {
                      mkdir(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      @chmod(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      }
           
            $fp     =fopen($folder.'/'.$photo,'wb');
                        fwrite($fp, base64_decode($base64));
                        fclose($fp);
                        @chmod($folder.'/' . $photo, 0777);


                   list($width, $height, $type, $attr) = getimagesize($folder.'/'.$photo);
                   

                  return $this->saveimage($width,$height,$folder.'/'.$photo,1,'','',$photo,1);
                   

           
           
           }
           
           function savephotolink($link,$widthcrop=0,$heightcrop=0)
           {
           $photo=mktime() .  '-' . rand(0, 10000) . '.jpg'; 

           //.'/'.$arrayimg['name'];
           $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
           $folder=cacheimgpath.'/user/'.$arrayuser['userid'];
           
            if(!is_dir(cacheimgpath.'/user/'.$arrayuser['userid']))
                     {
                      mkdir(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      @chmod(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      }
                      
                      
            if(filter_var($link, FILTER_VALIDATE_URL) !== FALSE)
            {

               // $img = file_get_contents($this->post['url']);
//                file_put_contents(cacheimgpath.'/user/'.$arrayuser['userid'].'/'.$newfile, $img);
            
            
            if(@copy($link,$folder.'/'.$photo))
                  {
                  @chmod($folder.'/' . $photo, 0777);
                        
                  }
                  
            }


                   
                   $fileName=$folder.'/'.$photo;
                   if($widthcrop||$heightcrop)
                   {
                   $this->cropimage($fileName,$widthcrop,$heightcrop,$fileName);
                   
                   }
                  list($width, $height, $type, $attr) = getimagesize($folder.'/'.$photo);    

                  return $this->saveimage($width,$height,$folder.'/'.$photo,1,'','',$photo,1);
                   

           
           
           }
           
           function savephotopath($path,$widthcrop=0,$heightcrop=0)
           {
           $photo=mktime() .  '-' . rand(0, 10000) . '.jpg'; 

           //.'/'.$arrayimg['name'];
           $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
           $folder=cacheimgpath.'/user/'.$arrayuser['userid'];
           
            if(!is_dir(cacheimgpath.'/user/'.$arrayuser['userid']))
                     {
                      mkdir(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      @chmod(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      }
                      
                      
            if(is_file($path))
            {

               // $img = file_get_contents($this->post['url']);
//                file_put_contents(cacheimgpath.'/user/'.$arrayuser['userid'].'/'.$newfile, $img);
            
            
            if(@copy($path,$folder.'/'.$photo))
                  {
                  @chmod($folder.'/' . $photo, 0777);
                        
                  }
                  
            }


                   
                   $fileName=$folder.'/'.$photo;
                   if($widthcrop||$heightcrop)
                   {
                   $this->cropimage($fileName,$widthcrop,$heightcrop,$fileName);
                   
                   }
                  list($width, $height, $type, $attr) = getimagesize($folder.'/'.$photo);    

                  return $this->saveimage($width,$height,$folder.'/'.$photo,1,'','',$photo,1);
                   

           
           
           }
           
           function getpluginfeature()
           {
           $sql="select * from tb_plugins where tb_plugins.show=1";
           $arrayfeature=$this->db->db_set_recordset($sql);
           return $arrayfeature;
           
           
           }
           
           
           function savetagrelatedata($tag,$productid)
           {
                      $sql='select fid,createby,productid from tb_product where productid='.$productid;
                      $arrayproduct=$this->db->db_set_1recordrow($sql);
                      
                      if($arrayproduct['productid'])
                      {
                      $tag=trim($tag);
                      if($tag)
                      {
                      $sql='select tagid from tb_tag where tb_tag.name="'.$tag.'" ';
                      $arraytag=$this->db->db_set_1recordrow($sql);
                      if($arraytag['tagid'])
                      {
                      $tagid=$arraytag['tagid'];
                      }else
                      {
                      $arraytag2=array();
                      $arraytag2['name']=$tag;
                      $arraytag2['fid']=$arrayproduct['fid'];
                      $arraytag2['createby']=$arrayproduct['createby'];
                      $arraytag2['createdate']=date("Y-m-d H:i:s");
                      $this->db->db_set($arraytag2,'tb_tag');
                      $tagid=$this->db->db_get_last_number();
                      }
                      
                      
                     $sql='select rtagid from tb_relate_tag where tb_relate_tag.tagid='.$tagid.' and tb_relate_tag.productid='.$productid;
                     $arrayrtag=$this->db->db_set_1recordrow($sql); 
                     if($arrayrtag['rtagid'])
                     {
                     
                     
                     
                     }else
                     {
                     $arraytag2=array();
                     $arraytag2['productid']=$productid;
                     $arraytag2['tagid']=$tagid;
                     $arraytag2['createby']=$arrayproduct['createby'];
                     $arraytag2['createdate']=date("Y-m-d H:i:s");
                     $this->db->db_set($arraytag2,'tb_relate_tag');
                     
                     
                     
                     }
                      
                      
                      
                      }
                      
                      }
           
           
           }
           
           
           
           function getfeaturebyname($name)
           {
           
             if(count($this->info['configall']['feature']))
             {
             foreach($this->info['configall']['feature'] as $valuefeature)
             {
               if($valuefeature['link']==strtolower($name))
               {
                 unset($valuefeature['plugins']);
                 return $valuefeature;
               
               }
             
             }
              
             }
             
             return array();
           
           
           }
           
           
           function getfeaturenamebyfid($fid)
           {
             
             if(count($this->info['configall']['feature']))
             {
             foreach($this->info['configall']['feature'] as $valuefeature)
             {
                 
               if($valuefeature['fid']==$fid)
               {
                 unset($valuefeature['plugins']);
                 return $valuefeature['name'];
               
               }
             
             }
              
             }
             
           //  return array();
           
           
           }
           
           
           function add2cartproduct($userid,$productid,$qty)
           {
           
            $sql='select * from tb_product_shop_history where userid='.$userid.' and productid='.$productid.' and tb_product_shop_history.delete=0 and status=0 and createby='.$this->userdata['userid'];
            $arraycart=$this->db->db_set_1recordrow($sql);
            if($arraycart['shisid'])
            {
            
            $qtity=$arraycart['quantity'];
            $newqtity=intval($qtity)+intval($qty);
            $arraydata['updatedate']=date("Y-m-d H:i:s");
            $arraydata['quantity']=$newqtity;
            $this->db->db_set($arraydata,'tb_product_shop_history',' shisid='.$arraycart['shisid']);
            
            }else
            {
            
            $arraydata['quantity']=$qty;
            $arraydata['userid']=$userid;
            $arraydata['productid']=$productid;
            $arraydata['createby']=$this->userdata['userid'];
            $arraydata['createdate']=date("Y-m-d H:i:s");
            
            $this->db->db_set($arraydata,'tb_product_shop_history');
            }
            
            
            $sql='select count(*) as countproduct from tb_product_shop_history where  tb_product_shop_history.delete=0 and status=0 and createby='.$this->userdata['userid'];;
            
            $arraycart2=$this->db->db_set_1recordrow($sql);
            
            
            return intval($arraycart2['countproduct']);
           
           }
           
           function getcarthistory($userid)
           {
           
           $sql='SELECT
tb_product_shop_history.shisid,
tb_product_shop_history.userid,
tb_product_shop_history.productid,
tb_product_shop_history.quantity,
IF (tb_product_setting.shopname is NULL,tb_user.displayname,tb_product_setting.shopname) as displayname,
tb_product.title,
tb_product.simgmid,

(select tb_plugins_pricefull.userpoint from tb_plugins_pricefull where tb_plugins_pricefull.productid=tb_product_shop_history.productid  ) as userpoint,


(select tb_plugins_pricefull.point from tb_plugins_pricefull where tb_plugins_pricefull.productid=tb_product_shop_history.productid  ) as point,


(select tb_plugins_pricefull.realprice from tb_plugins_pricefull where tb_plugins_pricefull.productid=tb_product_shop_history.productid  ) as price,
tb_user.simgmid as usimgmid,
tb_user.username,
tb_product_shop_history.`status`,
tb_product_shop_history.`delete`,
tb_product_shop_history.paypoint,
tb_product_shop_history.orderid,
tb_product_shop_history.suborderid,
tb_product_shop_history.updatedate,
tb_product_shop_history.createdate,
tb_product_shop_history.createby
FROM
tb_product_shop_history
INNER JOIN tb_user ON tb_product_shop_history.userid = tb_user.userid
INNER JOIN tb_product ON tb_product.productid=tb_product_shop_history.productid 

LEFT JOIN tb_product_setting ON tb_user.userid = tb_product_setting.createby

where tb_product_shop_history.createby='.$userid.' and tb_product_shop_history.status=0 and tb_product.status=1 and tb_product_shop_history.delete=0
order by tb_product_shop_history.userid desc';


$arraydata=$this->db->db_set_recordset($sql);

$arraynewdata=array();

if(count($arraydata))
{

foreach($arraydata as $valuedata)
{
$valuedata['simg']=$this->getimagebyimgmid($valuedata['simgmid']);
$valuedata['usimg']=$this->getimagebyimgmid($valuedata['usimgmid']);




$valuedata['priceall']=intval($valuedata['price'])*intval($valuedata['quantity']);

$valuedata['transport']=$this->gettransportdata($valuedata['userid']);

$arraynewdata[$valuedata['userid']]['username']=$valuedata['username'];
$arraynewdata[$valuedata['userid']]['usimg']=$valuedata['usimg'];
$arraynewdata[$valuedata['userid']]['displayname']=$valuedata['displayname'];
$arraynewdata[$valuedata['userid']]['transport']=$valuedata['transport'];
$arraynewdata[$valuedata['userid']]['userid']=$valuedata['userid'];
$arraynewdata[$valuedata['userid']]['orderid']=$valuedata['orderid'];

unset($valuedata['displayname']);
unset($valuedata['usimg']);
unset($valuedata['username']);
unset($valuedata['transport']);
unset($valuedata['orderid']);



$arraynewdata[$valuedata['userid']]['data'][$valuedata['productid']]=$valuedata;





}

}


           return $arraynewdata;
           
           }
           
           function gettransportdata($userid)
           {
           $sql='select * from tb_product_transport where createby='.$userid.' and tb_product_transport.delete=0';
           $arraydata=$this->db->db_set_recordset($sql);
           return $arraydata;
           
           
           
           }
           
           
           
           function getpoint($userid)
           {
           
           $sql='select point from tb_game_score where userid='.$userid;
           $arraypoint=$this->db->db_set_1recordrow($sql);
           $point=0;
           if($arraypoint['point'])
           {
           $point=intval($arraypoint['point']);
           }
           return $point;
           
           }
           
           function getproductbycondition($where="",$limit="",$orderby="",$innerjoin="",$groupby="",$select="",$nomemcache=0)
           {
                $roleadmin='';
            if($this->userdata['oauth'])
             {
                if($this->userdata['roleid']=='3')
                {
                
                $roleadmin='&roleadmin';
                
                }
                
             
             }
            $arraydata=array(); 
            $strdataquery=http_build_query($_GET);   
            if($nomemcache==0)
            {
            
            
            
            $arraydata=$this->memcache->get($strdataquery.$roleadmin) ;
            }
            
             if(count($arraydata)==0)
            {
            if($_GET['fid']=='0')
            {
            if($orderby==1)
            {
            $orderby=' order by tb_product.createdate desc';
            }
              $sql=" select tb_product.*,DATE_FORMAT(tb_product.createdate,'%d/%m/%Y') newdatecreate,DATE_FORMAT(tb_product.createdate,'%d/%m/%Y') newdate,DATE_FORMAT(tb_product.createdate,'%l.%i %p') timedate,tb_user.etc,IF (tb_user.displayname = '', tb_user.username,tb_user.displayname) as displayname,tb_user.username,tb_user.imgmid as userimgmid,tb_user.simgmid as usersimgmid $select  from tb_product 
            inner join tb_user ON tb_user.userid=tb_product.createby  
            $innerjoin
            $where 
            $groupby 
            $orderby 
            $limit";
            }
             else if($orderby==1)
            {
            $sql=" 
            SELECT * FROM (
            (
            
            select tb_product.*,DATE_FORMAT(tb_product.createdate,'%d/%m/%Y') newdatecreate,tb_product.position  as position2,DATE_FORMAT(tb_product.createdate,'%d/%m/%Y') newdate,DATE_FORMAT(tb_product.createdate,'%l.%i %p') timedate,tb_user.etc,IF (tb_user.displayname = '', tb_user.username,tb_user.displayname) as displayname,tb_user.username,tb_user.imgmid as userimgmid,tb_user.simgmid as usersimgmid $select  from tb_product 
            inner join tb_user ON tb_user.userid=tb_product.createby  
            $innerjoin
            $where  and  tb_product.position >0 
            $groupby
            
            ORDER BY tb_product.position asc
            )
            
            UNION
          (  
            select * from 

           (select tb_product.*,DATE_FORMAT(tb_product.createdate,'%d/%m/%Y') newdatecreate,9999999 as position2,DATE_FORMAT(tb_product.createdate,'%d/%m/%Y') newdate,DATE_FORMAT(tb_product.createdate,'%l.%i %p') timedate,tb_user.etc,IF (tb_user.displayname = '', tb_user.username,tb_user.displayname) as displayname,tb_user.username,tb_user.imgmid as userimgmid,tb_user.simgmid as usersimgmid  $select   from tb_product 
            inner join tb_user ON tb_user.userid=tb_product.createby  
            $innerjoin
            $where and  tb_product.position =0 
            $groupby
            
            order by tb_product.createdate desc 
            )  tb_product
            )
            ) tb_test2
            
ORDER BY tb_test2.position2 asc ,tb_test2.updatedate desc
            $limit
            
            ";
            }else
            {
            
             $sql=" select tb_product.*,DATE_FORMAT(tb_product.createdate,'%d/%m/%Y') newdatecreate,DATE_FORMAT(tb_product.createdate,'%d/%m/%Y') newdate,DATE_FORMAT(tb_product.createdate,'%l.%i %p') timedate,tb_user.etc,IF (tb_user.displayname = '', tb_user.username,tb_user.displayname) as displayname,tb_user.username,tb_user.imgmid as userimgmid,tb_user.simgmid as usersimgmid $select  from tb_product 
            inner join tb_user ON tb_user.userid=tb_product.createby  
            $innerjoin
            $where 
            $groupby 
            $orderby 
            $limit";
            
            }
            
           
            

//exit;
            if($_GET['admincheck'])
            {
            echo $sql;
            exit;
            }
           // $this->arraydata['sql2']=$sql;
           

            $data=$this->db->db_set_recordset($sql);
               

            if(count($data))
            {
            foreach($data as $valuedata)
            {
            
                 
                
                $valuedata['title']=stripslashes($valuedata['title']);
                $valuedata['link']=urlencode($valuedata['link']);
                $valuedata['description']=stripslashes($valuedata['description']);

                
                
                 $valuedata['otherproduct']=$this->getotherlandingbyuserid($valuedata['createby']);
                 $valuedata['relateproduct']=$this->getrelatebyproductid($valuedata['productid']);
                
                
                 $valuedata['countlike']=$this->countfav($valuedata['productid']);
                 $valuedata['checklike']=  $this->checkuserfav($valuedata['productid'],$this->userdata['oauth']);  
                 $valuedata['countview']=$this->countview($valuedata['productid']);
                 
                 
                 $valuedata['checkbookmark']=  $this->checkuserlike($valuedata['productid'],$this->userdata['oauth']); 
                 $valuedata['countbookmark']=  $this->countlike($valuedata['productid']);
                 
                 

                 
                 
                 $valuedata['countcomment']=$this->countcomment($valuedata['productid']); 
                 $valuedata['countfollow']=$this->countfollower($valuedata['createby']);  
                 $valuedata['checkfollow']=$this->checkuserfollow($valuedata['createby'],$this->userdata['oauth']);
                 
                 
                 
                 $valuedata['usersimg']= $this->getimagebyimgmid($valuedata['usersimgmid']);
                 $valuedata['userssimg']= $this->getimagebyimgmid($valuedata['usersimgmid']);
                 
                
                 $valuedata['img']= $this->getimagebyimgmid($valuedata['imgmid']);
                 $valuedata['simg']= $this->getimagebyimgmid($valuedata['simgmid']);
                 
                 $valuedata['tag']=$this->gettagbyproductid($valuedata['productid']);
  
                $valuedata['taguser']=$this->gettagbytaguser($valuedata['tag'],$valuedata['createby']);
                 //echo $valuedata['fid']."\n";
                 $valuedata['feature']=$this->getfeaturebyfid($valuedata['fid']);
                 //echo $valuedata['fid']."\n";
//                 echo "\n\n<pre>";
//                 print_r($valuedata['feature']);
//                 echo "</pre>;\n\n";
                 
                  if($valuedata['iscredit']=='1')
                 {
                 $valuedata['plugins'][0]['plugid']=38;
                 $valuedata['plugins'][0]['plugname']='credit';
                 $valuedata['plugins'][0]['credit']=$valuedata['credit'];
                 $valuedata['plugins'][0]['productid']=$valuedata['productid'];
                 

                 
                 }else
                 {
                 
                 $valuedata['plugins']=$this->getplugins($valuedata['productid']);
                 
                 
                 if(count($valuedata['plugins']))
                 {
                 
                 foreach($valuedata['plugins'] as $valueplugin)
                 {
                 

                 if($valuedata['feature']['showmainplugid'])
                 {
                 if(array_search($valueplugin['plugid'],$valuedata['feature']['showmainplugid'])!==false)
                 {
                 
                 $valuedata['show'][$valueplugin['plugname']]=$valueplugin['show'];
                 
                 
                 }
                 }
                 
                 if($valueplugin['plugid']=='9')
                 {
                 
                 $valuedata['type']=$valueplugin['type'];
                 $valuedata['size']=$valueplugin['file']['size'];
                 
                 }
                 
                 if($valueplugin['plugid']=='25')
                 {
                 
                 $valuedata['type']='zave';
                 $valuedata['size']=$valueplugin['filezave']['size'];
                 
                 }
                 if($valueplugin['plugid']=='20')
                 {
                 
                 $valuedata['type']='mp4';
                 $valuedata['size']=$valueplugin['file']['size'];
                 
                 }
                 
                 }
                 
                 
                 
                 }
                 }
                
                 
                 
                 
                 
                 
                 
                 
                 
              
              
            
            
              $arraydata[]=$valuedata;
            }
            
            
            }
            if($nomemcache==0)
            {
            $this->memcache->set($strdataquery.$roleadmin,$arraydata) ; 
            }
            
            }
            else
            {

            $k=0;
            foreach($arraydata as $valuedata2)
            {
                   $arraydata[$k]['countlike']=$this->countfav($valuedata2['productid']);
                    $arraydata[$k]['checklike']=  $this->checkuserfav($valuedata2['productid'],$this->userdata['oauth']); 
                    $arraydata[$k]['checkfollow']=$this->checkuserfollow($valuedata2['createby'],$this->userdata['oauth']);  
                    $arraydata[$k]['checkbookmark']=  $this->checkuserlike($valuedata2['productid'],$this->userdata['oauth']);
                    
                    $arraydata[$k]['countcomment']=$this->countcomment($valuedata2['productid']);  
                    
                    $k++;
            
            
            
            }
            
            
            }
            
            return $arraydata;
           
           }
           
           function getproductbyconditionshort($page,$userid=0,$fid=0,$nomemcache=0)
           {
           
            $strdataquery=http_build_query($_GET);
            $page=(($page - 1) * countpage);  
            $limit="limit  $page,".countpage; 
            $arraydata=array();
            if($nomemcache==0)
            {
            $arraydata=$this->memcache->get($strdataquery.$userid.$fid.'cache') ;
            }
            
            
             if(count($arraydata)==0)
            {

            $where='where tb_product.status=1 and tb_product.`delete`=0 and tb_product.createdate < "'.date('Y-m-d H:i:s').'" ';
            if($fid)
            {
            $where.=' and  tb_product.fid='.$fid;
            }
            
            if($userid)
            {
            $where.=' and  tb_product.createby='.$userid;
            }
            
            $sql=" select tb_product.productid,tb_product.link,tb_product.title from tb_product $where  order by tb_product.createdate desc $limit";
            //echo $sql;
//            exit;
            
            

            $arraynewdata=$this->db->db_set_recordset($sql);
            $arraydata=array();
            $krow=0;
            $arraydata['data']=array();
            if(count($arraynewdata))
            {
            foreach($arraynewdata as $valuedata)
            {
            $arraydata['data'][$krow]['link']=baseinfo.'/'.$valuedata['link'].'/'.$valuedata['productid'];
            $arraydata['data'][$krow]['title']=$valuedata['title'];
            $arraydata['data'][$krow]['url']=$valuedata['link'];
            
            $krow++;
            
            }
            
            }
            
             $sql=" select count(tb_product.productid) as rownumber from tb_product $where ";
            $arraynewdata2=$this->db->db_set_1recordrow($sql);
            
            
             $arraydata['numpage']=ceil(intval($arraynewdata2['rownumber'])/countpage);
            
             if($nomemcache==0)
            {
            $this->memcache->set($strdataquery.$userid.$fid.'cache',$arraydata) ; 
            }
            
            
            }
            
           return $arraydata;
            
           
           
           }
           
           function likefunction($productid,$oauth)
           {
            $userdata=$this->getuserbyoauth($oauth);
            if($userdata['userid'])
            {
           $sql="SELECT
                    tb_like.lid,tb_like.status
                    FROM
                    tb_like
                    INNER JOIN tb_user ON tb_like.createby = tb_user.userid
                    where tb_like.productid=".$productid." and tb_user.oauth='".$oauth."' ";
           
           $data=$this->db->db_set_1recordrow($sql);  
           $arraydata=array(); 
           $arraydata['updateby']=$userdata['userid'];
            
           $arraydata['updatedate']=date("Y-m-d H:i:s"); 
           
           if($data['lid'])
           {
           
           if($data['status']==1)
           {
           $arraydata['status']=2;
           $this->db->db_set($arraydata,'tb_like',' lid='.$data['lid']); 
           }else
           {
           
          $arraydata['status']=1;
          $this->db->db_set($arraydata,'tb_like',' lid='.$data['lid']);  
           
           }
           
           return true;
           
           
           }else
           {
           
           
           
           
             $arraydata['status']=2;
             $arraydata['productid']=$productid;
             $arraydata['createdate']=date("Y-m-d H:i:s");
             $arraydata['createby']=$userdata['userid'];
             $this->db->db_set($arraydata,'tb_like');  
             $lid=$this->db->db_get_last_number();
           
           $sql="select tb_product.productid,tb_product.title,tb_product.createby from tb_product   where tb_product.productid=".$productid;
           $dataproduct=$this->db->db_set_1recordrow($sql);  
           $userid=$dataproduct['createby']; 
           $arraydataset['userid']=$userid;
           $arraydataset['createby']=$userdata['userid'];
           $arraydataset['conid']=39;
           $arraydataset['lid']=$lid;
           $notiid[$userid]=$this->savenotificationlist($arraydataset);
            
            $this->savegamenictaionbygxcid($userdata['userid'],9);
            
           $msgto=$userdata['displayname'].' '.$this->getconditionmsgbyid(39).' '.$dataproduct['title'];
           $arraydatanow[]=$userid;
           $this->sendtonotification($arraydatanow,$msgto,$notiid);
             
             return true;
             
             
           
            
          
           
           
           }
           
           
           
            }else
            {
             return false;  
            
            }
           
           }
           
           function followuserfunction($userid,$oauth)
           {
             $userdata=$this->getuserbyoauth($oauth);
             
             
            if(($userdata['userid']&&$userid)&&$userdata['userid']!=$userid)
            {
            
             $sql="
                    SELECT
                    tb_follow.foid,tb_follow.status,tb_follow.block
                    FROM
                    tb_follow
                    where tb_follow.createby=".$userdata['userid'].' and tb_follow.userid='.$userid;

             $data=$this->db->db_set_1recordrow($sql);  

           $arraydata=array(); 
           $arraydata['updateby']=$userdata['userid'];
           
           $arraydata['updatedate']=date("Y-m-d H:i:s");
           
           $sql="select publish from tb_user where tb_user.userid=".$userid;
           $datacheckuser=$this->db->db_set_1recordrow($sql);  
           
           if($data['foid'])
           {
           if($datacheckuser['publish']==0)
           {
           if($data['status']==1)
           {
           $arraydata['status']=3;
           $this->db->db_set($arraydata,'tb_follow',' foid='.$data['foid']); 
           
           }else if($arraydata['status']==3)
           {
           
           $arraydata['status']=1;
           $this->db->db_set($arraydata,'tb_follow',' foid='.$data['foid']); 
           }else if($arraydata['block']==1)
           {
           
           //$arraydata['status']=1;
          // $this->db->db_set($arraydata,'tb_follow',' foid='.$data['foid']); 
           }else
           {
           $arraydata['status']=1;
           $this->db->db_set($arraydata,'tb_follow',' foid='.$data['foid']); 
           
           }
           
           }
           else
           {
            if($data['status']==1)
           {
           $arraydata['status']=2;
           $this->db->db_set($arraydata,'tb_follow',' foid='.$data['foid']); 
           }else 
           {
           
          $arraydata['status']=1;
          $this->db->db_set($arraydata,'tb_follow',' foid='.$data['foid']);  
           
           }
           
           }
           return true;
           
           }else
           {
            if($datacheckuser['publish']==0)
           {
           $arraydata['status']=3;
           $conid=37;

           
           
           }else
           {
           $arraydata['status']=2;
           
           $conid=1;
           
           
           }
           
           $arraydata['userid']=$userid;
           $arraydata['createdate']=date("Y-m-d H:i:s");
           $arraydata['createby']=$userdata['userid'];
           $this->db->db_set($arraydata,'tb_follow');
           $foid=$this->db->db_get_last_number(); 
           
           $this->savegamenictaionbygxcid($userdata['userid'],5);
           $this->savegamenictaionbygxcid($userid,6);
           
           $arraydataset['userid']=$userid;
           $arraydataset['createby']=$userdata['userid'];
           $arraydataset['conid']=$conid;
           $arraydataset['foid']=$foid;
           $notiid[$userid]=$this->savenotificationlist($arraydataset);
           
           $msgto=$userdata['displayname'].' '.$this->getconditionmsgbyid($conid);
           $arraydatanow[]=$userid;
           $this->sendtonotification($arraydatanow,$msgto,$notiid);
           
           
           return true;
           
           }
            
            }
            else
            {
            
            return false;
            }
           
           
           }
           
           function acceptuserfunction($userid,$oauth)
           {
           $userdata=$this->getuserbyoauth($oauth);
             
             
            if(($userdata['userid']&&$userid)&&$userdata['userid']!=$userid)
            {
            
             $sql="
                    SELECT
                    tb_follow.foid,tb_follow.status
                    FROM
                    tb_follow
                    where tb_follow.createby=".$userid.' and tb_follow.userid='.$userdata['userid'];

             $data=$this->db->db_set_1recordrow($sql);  

           $arraydata=array(); 
           $arraydata['updateby']=$userdata['userid'];
           
           $arraydata['updatedate']=date("Y-m-d H:i:s");
           

           
           if($data['foid'])
           {
          
           
           $arraydata['status']=2;
           $this->db->db_set($arraydata,'tb_follow',' foid='.$data['foid']);
           return true;
           
           }else
           {
           return false;
           
           }
            
            }
            else
            {
            
            return false;
            }
           
           }
           
           function blockuserfunction($userid,$oauth,$status)
           {
           $userdata=$this->getuserbyoauth($oauth);
             
             
             
             
            if(($userdata['userid']&&$userid)&&$userdata['userid']!=$userid)
            {
            
            switch ($status) {
            case 3:
                // requert user follower
               // $where="select tb_follow.createby as userid from tb_follow  where userid=".$userdata['userid']." and tb_follow.status=3 limit $page,20";
                $where="tb_follow.createby=".$userid.' and tb_follow.userid='.$userdata['userid'];
                
                break;
            case 1:
               //  follower
                //$sql="select tb_follow.createby as userid from tb_follow  where userid=".$userdata['userid']." and tb_follow.status=2 limit $page,20";
                $where="tb_follow.createby=".$userid.' and tb_follow.userid='.$userdata['userid'];
                break;
            case 2:
                //  following
                 $where="tb_follow.createby=".$userdata['userid'].' and tb_follow.userid='.$userid;

                break;
            case 4:
            
                 $where="tb_follow.createby=".$userid.' and tb_follow.userid='.$userdata['userid'];
               //  block user
                //$sql="select tb_follow.createby as userid from tb_follow  where userid=".$userdata['userid']." and (tb_follow.status=4 or tb_follow.status=5) limit $page,20";

                break;
            }
            
             $sql="
                    SELECT
                    tb_follow.foid,tb_follow.status,tb_follow.block
                    FROM
                    tb_follow
                    where ".$where;
             
   
             $data=$this->db->db_set_1recordrow($sql);  

           $arraydata=array(); 
           $arraydata['updateby']=$userdata['userid'];
           
           $arraydata['updatedate']=date("Y-m-d H:i:s");
           

           
           if($data['foid'])
           {
           if($data['block']==1)
           {
           
           $arraydata['block']=0;
           $this->db->db_set($arraydata,'tb_follow',' foid='.$data['foid']);
           
           }else if($data['block']==0)
           {
           
           $arraydata['block']=1;
           $this->db->db_set($arraydata,'tb_follow',' foid='.$data['foid']);
           
           }
           
           
           
           return true;
           
           }else
           {
           return false;
           
           }
            
            }
            else
            {
            
            return false;
            }
           
           }
           
           function sendtonotification($userids=array(),$msg,$notiid=array())
           {
           
                //$msg="$strset Book ".$this->post['title'];
                if(strlen($msg)>100)
                {
                $msg=mb_substr(addslashes($msg),0,27,'UTF-8').'...';
                
                }
           
           if(count($userids))
           {
           $strjoin='('.join(",",$userids).')';
           
           foreach( $userids as $valueuserid )
           {
           $sql="UPDATE tb_user SET tb_user.badge=tb_user.badge+1 where tb_user.userid=".$valueuserid;
           $this->db->db_set_execute($sql);
           
           }
           
           
           $sql='SELECT
           tb_token.token,
           tb_token.status,
           tb_user.userid,
           tb_user.badge
           FROM
           tb_user
           INNER JOIN tb_token ON tb_user.userid = tb_token.userid
           where tb_user.userid IN '.$strjoin.'
           order by tb_token.tokenid desc
           ';
          $arraydata= $this->db->db_set_recordset($sql);
          $arraydataandroid=array();
          $arraydataios=array();
          if(count($arraydata))
          {
          $k=0;
          foreach($arraydata as $valuetoken)
          {
               $strcheckdata=substr($valuetoken['token'],0,2);
          
               if($strcheckdata=="AP"&&$valuetoken['status']==1)
                {
                $arraydataandroid[]=$valuetoken['token'];
                
                }else if($valuetoken['token']!="1"&&$valuetoken['status']==1)
                {
                
                $arraydataios[$k]['token']=$valuetoken['token'];
                $arraydataios[$k]['badge']=$valuetoken['badge'];
                $arraydataios[$k]['type']=1;
                $arraydataios[$k]['notiid']=$notiid[$valuetoken['userid']]; 

                $k++;
                
                }
          
          
          }
          if(count($arraydataios))
          {
          if($this->info['configall']['store'])
          {
           $pempath=pempath.'/'.$this->info['configall']['pempro'];
           $gateway="gateway.push.apple.com:2195";
          
          }else
          {
            $pempath=pempath.'/'.$this->info['configall']['pemdev'];
            $gateway="gateway.sandbox.push.apple.com:2195";  
          
          }

            $passphrase=$this->decodetext($this->info['configall']['pempassword']);
            $passphrase=trim($passphrase);
            $this->pushnotification($arraydataios,$pempath,$passphrase,$msg,$gateway);
          }
          if(count($arraydataandroid))
          {
          $pass=$this->decodetext($this->info['configall']['googlepassword']);
          $this->pushnotificationandroid($arraydataandroid,$msg,$pass);
          }
          
          }
          
          
          
          
           
           }
           
           }
           
           function pushnotificationandroid($arraydata,$msg,$pass)
          {
          
          if(count($arraydata))
          {
          $apiKey=$pass;
          $url = 'https://android.googleapis.com/gcm/send';

          $fields = array(
                        'registration_ids'  => $arraydata,
                        'data'              => array( "message" => $msg ),
                        );
          $headers = array( 
                    'Authorization: key=' . $apiKey,
                    'Content-Type: application/json'
                );
     
                
           $ch = curl_init();

            curl_setopt( $ch, CURLOPT_URL, $url );

            curl_setopt( $ch, CURLOPT_POST, true );
            curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

            curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );

            // Execute post
            $result = curl_exec($ch);

            // Close connection
            curl_close($ch);
            
            
           //echo $result;
          
          
          }
          
          }
          
          function getotherlandingbyuserid($userid)
          {
          
          $sql='select productid,title,simgmid,link from tb_product where createby='.$userid.' and tb_product.delete=0 and tb_product.status=1 and tb_product.createdate < "'.date('Y-m-d H:i:s').'" order by tb_product.createdate desc
  limit 0,6';
          $arraylanding=$this->db->db_set_recordset($sql);
          $k=0;
          if(count($arraylanding))
          {
          foreach($arraylanding as $valuelanding)
          {
          //$arraylanding[$k]['img'];
          $arraylanding[$k]['img']= $this->getimagebyimgmid($valuelanding['simgmid']);
          $k++;
          
          }
          
          }
          return $arraylanding;
          }
          
          
          function getrelatebyproductid($productid)
          {
          
          $sql='select tagid from tb_relate_tag where productid='.$productid;
          $arraylanding=$this->db->db_set_recordset($sql);
          
          if(count($arraylanding))
          {
          
          $arraytag=array();
          foreach($arraylanding as $valuelanding)
          {
          $arraytag[]=$valuelanding['tagid'];
          
          
          }
          
          $strtag=join(',',$arraytag);
          
          $sql='SELECT 
tb_product.productid,title,simgmid,link
FROM
tb_relate_tag
INNER JOIN tb_product ON tb_relate_tag.productid = tb_product.productid
where tb_relate_tag.tagid IN ('.$strtag.') and tb_product.delete=0 and tb_product.status=1 and tb_product.createdate < "'.date('Y-m-d H:i:s').'"
GROUP BY tb_relate_tag.productid
order by tb_product.createdate desc
limit 0,6
 ';
          $arraylanding2=$this->db->db_set_recordset($sql);
          
          
          $k=0;
          if(count($arraylanding2))
          {
          foreach($arraylanding2 as $valuelanding)
          {
          //$arraylanding[$k]['img'];
          $arraylanding2[$k]['img']= $this->getimagebyimgmid($valuelanding['simgmid']);
          $k++;
          
          }
          $arraylanding=$arraylanding2;
          }else
          {
          $arraylanding=array();
          }
          
          
          }else
          {
          $arraylanding=array();
          
          }
          
          
          return $arraylanding;
          }
          
           
           function pushnotification($arraydata,$pempath,$passphrase,$msgto,$gateway)
          {

           
      //  $gateway="gateway.push.apple.com:2195";    
       // $gateway="gateway.sandbox.push.apple.com:2195";           
         // echo     $pempath."\n";
         // echo $passphrase."\n";
        if(is_file($pempath))
        {

              // echo     'test'."\n";
       // echo rootpathbasemain.'/pem/'.folderpath.'/'.$pem.'/'.$pem.'.pem'; 
            $ctx = @stream_context_create();
            @stream_context_set_option($ctx, 'ssl', 'local_cert', $pempath);
            @stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);


        $fp = @stream_socket_client(
        'ssl://'.$gateway, $err,
        $errstr, 120, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

        if (!$fp)
        //exit("Failed to connect: $err $errstr" . PHP_EOL);
        $k=0;
        
        foreach($arraydata as $valuedata)
        {
        //$body['aps']=$valuedata;
        
        $body['aps']['alert']=$msgto;  
        $body['aps']['type']=$valuedata['type'];
        $body['aps']['notiid']=$valuedata['notiid'];
        $body['aps']['badge']=intval($valuedata['badge']);
        $body['aps']['sound']='default';
        
        
     //   echo "<pre>";
//        print_r($body);
//        echo "</pre>;";

       // $body['aps'] = array(
//        'alert' => $message,
//        'type' => $type,
//        'sound' => 'default',
//        'badge' => $badge,
//        'mid'=> $mid
//        );

//         echo           $valuedata['token'];
    // Encode the payload as JSON
        $payload = json_encode($body);

    // Build the binary notification
        $msg = chr(0) . pack('n', 32) . pack('H*', $valuedata['token']) . pack('n', strlen($payload)) . $payload;
    //    echo       $deviceToken."<br>";
    // Send it to the server
        if(@fwrite($fp, $msg, strlen($msg)))
        {
        //  echo    "1==>".$valuedata['token']."\n";
              // $result = fwrite($fp, $msg, strlen($msg)); 
        }else
        {
       //    echo    "2==>".$valuedata['token']."\n";
           @fclose($fp);
           $ctx = @stream_context_create();
            @stream_context_set_option($ctx, 'ssl', 'local_cert', $pempath);
            @stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
            
           $fp = @stream_socket_client(
        'ssl://'.$gateway, $err,
        $errstr, 120, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
        
        }
       
      
        
        $k++;
        }
       
        fclose($fp);
        }

          }
          
           
           function getlistuserbystatus($userid,$status,$page=1,$search="")
           {
           $page=(($page-1)*20);
           $arraynewdata=array();
        //   $userdata=$this->getuserbyoauth($oauth);
            $userdata['userid']= $userid;
           if($userdata['userid']&&$status)
            {
            
            
            switch ($status) {
            case 3:
                // requert user follower
                $sql="select tb_follow.createby as userid,tb_follow.updatedate from tb_follow  where userid=".$userdata['userid']." and tb_follow.status=3 and tb_follow.block=0 limit $page,20";
                
                
                break;
            case 1:
               //  follower
                $sql="select tb_follow.createby as userid,tb_follow.updatedate from tb_follow  where userid=".$userdata['userid']." and tb_follow.status=2 and tb_follow.block=0 GROUP BY createby   ORDER BY tb_follow.updatedate desc limit $page,20";

                break;
            case 2:
                //  following
                 $sql="select tb_follow.userid,tb_follow.updatedate from tb_follow  where createby=".$userdata['userid']." and tb_follow.status=2 and tb_follow.block=0 GROUP BY userid ORDER BY tb_follow.updatedate desc limit $page,20";

                break;
            case 4:
               //  block user
                $sql="select tb_follow.createby as userid,tb_follow.updatedate from tb_follow  where userid=".$userdata['userid']." and tb_follow.block=1 ORDER BY tb_follow.updatedate desc limit $page,20";

                break;
            case 5:
               //  block user
                $sql="select tb_follow.userid,tb_follow.updatedate from tb_follow  where createby=".$userdata['userid']." and tb_follow.block=1 ORDER BY tb_follow.updatedate desc limit $page,20";

                break;
             case 6:
                //  other user
               // $sql="select  IF(tb_follow.userid=".$userdata['userid'].",tb_follow.createby,tb_follow.userid) as userid  tb_follow.userid from tb_follow  where ( createby=".$userdata['userid']." or userid=".$userdata['userid']." ) and tb_follow.status=6 and tb_follow.block=0 limit $page,20";
                
                $sql="select
userid2 as userid,tb_follow.updatedate
from (
SELECT  
IF(tb_follow.userid=".$userdata['userid'].",tb_follow.createby,tb_follow.userid) as userid2,tb_follow.updatedate
from tb_follow  
where ( tb_follow.createby=".$userdata['userid']." or tb_follow.userid=".$userdata['userid']." ) and tb_follow.status=1 and tb_follow.block=0 
GROUP BY userid2
ORDER BY tb_follow.updatedate desc
) tb_follow
limit $page,20
";

                break;
              //  suggetion friend  
             case 7:
             
               // $sql='SELECT
//tb_follow.userid,tb_follow.updatedate,count(tb_follow.userid) as countfollow 
//FROM
//tb_follow
//where tb_follow.`status`=2 and ( tb_follow.userid !='.$userdata['userid'].' or tb_follow.createby !='.$userdata['userid'].'  )
//GROUP BY tb_follow.userid
//ORDER BY countfollow desc limit '.$page.',20';
                $innerjoin="";
                $where="";
               if($search)
               {
               $innerjoin=" inner join tb_user on tb_user.userid=tb_newuser.userid";
               $where=" and (tb_user.username like '%$search%' or  tb_user.displayname like '%$search%' )";
               } 

                $sql='
SELECT * from (

select * from (
SELECT tb_follow.userid
FROM tb_follow 
where tb_follow.`status`=2 
GROUP BY tb_follow.userid 
ORDER BY count(tb_follow.userid) desc 
) tb_follow

union 

select tb_user.userid
from tb_user
) tb_newuser 
'.$innerjoin.'
where 
tb_newuser.userid not in ( select tb_follow.userid from tb_follow where tb_follow.createby='.$userdata['userid'].' and tb_follow.`status`=2 )
and tb_newuser.userid!='.$userdata['userid'].'
'.$where.'
limit '.$page.',20';

            break;
            

            
            }
            
            
            //echo $sql;
            $arraydata=$this->db->db_set_recordset($sql);

            if(count($arraydata))
            {
            foreach($arraydata as $valuedata)
            {
            

                if($valuedata['userid'])
                 {
                 
                 $datauser=$this->getuserbyuserid($valuedata['userid'],",simgmid,etc");
                 
                 if(!$datauser['displayname'])
                 {
                    $datauser['displayname']=$datauser['username'];
                 }
                 if($datauser['userid'])
                 {
                 
                 

                 if($this->userdata['oauth'])
                 {
                 
                 
                 
                 $datauser['checkfollow']=$this->checkuserfollow($valuedata['userid'],$this->userdata['oauth']);
                 
//                 echo "follow \n";
//                 echo $valuedata['userid']."\n";
//                 echo $this->userdata['userid']."\n";
//                 echo $datauser['checkfollow']."\n";
//                 echo  "\n \n \n";
                 
                 }else
                 {
                 $datauser['checkfollow']=false;
                 }
                 $datauser['newupdatedate']=date( "F j, Y, g:i a",strtotime($valuedata['updatedate'])) ;
                 
                 $datauser['imgarray']=$this->getimagebyimgmid($datauser['imgmid']);
                 $datauser['simgarray']=$this->getimagebyimgmid($datauser['simgmid']);
                 
                 $arraynewdata[]=$datauser;
                 
                 
                 }
                 
                 }
                
            
            
            
            }
            
            
            
            
            }
            
            
            
            }
            
            return $arraynewdata;
            
          
           
           }
           
           function countfollower($userid)
           {
            $sql="
            SELECT count(*)  as countfollow
FROM (
SELECT
                    tb_follow.createby
                    FROM
                    tb_follow
                    where tb_follow.userid=".$userid." and tb_follow.status=2 and tb_follow.block=0  GROUP BY createby ) tb_b
";
           
           $data=$this->db->db_set_1recordrow($sql); 
           if($data['countfollow']=="")
           {
           $data['countfollow']=0;
           }
              $data['countfollow']=intval($data['countfollow']);
           return     $data['countfollow'];
           
           }
           
           function countfollowing($userid)
           {
            $sql="SELECT count(*) as countfollow from (
SELECT
                    tb_follow.userid
                    FROM
                    tb_follow
                    where tb_follow.createby=".$userid." and tb_follow.status=2 and tb_follow.block=0  GROUP BY tb_follow.userid ) tb_b";
           
           $data=$this->db->db_set_1recordrow($sql); 
           if($data['countfollow']=="")
           {
           $data['countfollow']=0;
           }
              $data['countfollow']=intval($data['countfollow']);
           return     $data['countfollow'];
           
           }
           
           function countrequests($userid)
           {
            $sql="SELECT
                    count(tb_follow.foid) as countfollow
                    FROM
                    tb_follow
                    where tb_follow.userid=".$userid." and tb_follow.status=3 and tb_follow.block=0 ";
           
           $data=$this->db->db_set_1recordrow($sql); 
           if($data['countfollow']=="")
           {
           $data['countfollow']=0;
           }
              $data['countfollow']=intval($data['countfollow']);
           return     $data['countfollow'];
           
           }
           
            function countblock($userid)
           {
            $sql="SELECT
                    count(tb_follow.foid) as countfollow
                    FROM
                    tb_follow
                    where tb_follow.userid=".$userid." and tb_follow.block=1";
           
           $data=$this->db->db_set_1recordrow($sql); 
           if($data['countfollow']=="")
           {
           $data['countfollow']=0;
           }
              $data['countfollow']=intval($data['countfollow']);
           return     $data['countfollow'];
           
           }
           
           function countblockfollowing($userid)
           {
            $sql="SELECT
                    count(tb_follow.foid) as countfollow
                    FROM
                    tb_follow
                    where tb_follow.createby=".$userid." and tb_follow.block=1";
           
           $data=$this->db->db_set_1recordrow($sql); 
           if($data['countfollow']=="")
           {
           $data['countfollow']=0;
           }
              $data['countfollow']=intval($data['countfollow']);
           return     $data['countfollow'];
           
           }
           
           function checkuserfollow($userid,$oauth="")
           {
           $userdata=$this->getuserbyoauth($oauth);
            if($userdata['userid'])
            {
           $sql="SELECT
                    tb_follow.foid,tb_follow.status
                    FROM
                    tb_follow
                    where tb_follow.userid=".$userid." and tb_follow.createby=".$userdata['userid'];

           $data=$this->db->db_set_1recordrow($sql); 
            
           if($data['foid'])
           {
             if($data['status']=="2")
           {
             return   true;
           }else   if($data['status']=="1") 
           {
             return   false;
           
           }
           else   if($data['status']=="3") 
           {
             return   3;
           
           }
           else   if($data['status']=="4") 
           {
             return   4;
           
           }
           
           }else
           {
             return   false;
           
           } 
            }else
            {
             return   false; 
            
            }  
           
           
           }
           
           function countlike($productid)
           {
           
           $sql="SELECT
                    count(tb_like.lid) as countlike
                    FROM
                    tb_like
                    where tb_like.productid=".$productid." and tb_like.status=2 ";
           
           $data=$this->db->db_set_1recordrow($sql); 
           if($data['countlike']=="")
           {
           
              $data['countlike']=0;
           }
              $data['countlike']=intval($data['countlike']);
           return     $data['countlike'];
           
           }
           
           function countview($productid)
           {
           
           $sql="SELECT
                    count(tb_view.viewid) as countview
                    FROM
                    tb_view
                    where tb_view.productid=".$productid." ";
           
           $data=$this->db->db_set_1recordrow($sql); 
           if($data['countview']=="")
           {
           
              $data['countview']=0;
           }
              $data['countview']=intval($data['countview']);
           return     $data['countview'];
           
           }
           
           function checkuserlike($productid,$oauth="")
           {
            $userdata=$this->getuserbyoauth($oauth);
            if($userdata['userid'])
            {
            $sql="SELECT
                    tb_like.lid,tb_like.status
                    FROM
                    tb_like
                    INNER JOIN tb_user ON tb_like.createby = tb_user.userid
                    where tb_like.productid=".$productid." and tb_user.oauth='".$oauth."' ";
           
           $data=$this->db->db_set_1recordrow($sql);
           if($data['lid'])
           {
             if($data['status']==2)
           {
             return   true;
           }else   if($data['status']==1) 
           {
             return   false;
           
           }
           
           }else
           {
             return   false;
           
           } 
            
            
            }else
            {
            
               return   false;
            
            }
           
           
           }
               
           function saveimage($width,$height,$path,$original="",$url="",$imgmid="",$imgname="",$cache="",$system="")
           {
              $newpath=str_replace(rootpath.'/','',$path);
              $newpath=str_replace(imgpath.'/','',$newpath);
              $newpath=str_replace(imginfo.'/','',$newpath);
              $arraydatanow=explode("/",$path);
              if($imgmid)$arraydataset['imgmid']=$imgmid;
              $arraydataset['name']=$arraydatanow[count($arraydatanow)-1];
              $arraydataset['url']=$url;
              $arraydataset['size']=filesize($path);
              $arraydataset['path']=$newpath;
              $arraydataset['imgname']=$imgname;
              if($cache)$arraydataset['cache']=$cache;
              if($system)$arraydataset['system']=$system;
              
              
              list($basewidth, $baseheight, $type, $attr) =getimagesize($path);
              
              $arraydataset['basewidth']=$basewidth;
              $arraydataset['baseheight']=$baseheight;
              
              $arraydataset['width']=$width;
              $arraydataset['height']=$height;
              if($original)
              {
              $arraydataset['conid']=6;
              }else
              {
              $arraydataset['conid']=$this->getconditionbysize($width,$height);
              }
              
              $arraydataset['status']=1;
              $arraydataset['createby']=$this->userdata['userid'];
              $arrayother=@exif_read_data(rootpath.'/'.$newpath, 0, true);
              $arraydataset['other']=@json_encode($arrayother);
              
              
              
              
              
              
              
              
              $arraydataset['createdate']=date("Y-m-d H:i:s");
              $imgmid=$this->saveimagedata($arraydataset);
              
              if($arraydataset['other']&&$arraydataset['other']!='false')
              {
              $sql="SHOW TABLES LIKE 'tb_img_setting'";
              $arraycheck=$this->db->db_set_1recordrow($sql);
              
              if(count($arraycheck))
                 {
               
                 
                 $otherdata=object_to_array($arrayother);
                 
                 if($otherdata['IFD0']['Make'])
                 {
                 $arraydata['imgmid']=$imgmid;
                 $arraydata['make']=$otherdata['IFD0']['Make'];
                 $arraydata['model']=$otherdata['IFD0']['Model'];
                 $arraydata['createdate']=date("Y-m-d H:i:s");
                 $this->db->db_set($arraydata,'tb_img_setting');
                 
                 }
                 
                 
                 
              
                 
                 }
              }
              
              
              
              return $imgmid;
             
           
           }
           function countfav($productid)
           {
           
           $sql="SELECT
                    count(tb_fav.favid) as countlike
                    FROM
                    tb_fav
                    where tb_fav.productid=".$productid." and tb_fav.status=2 ";
           
           $data=$this->db->db_set_1recordrow($sql); 
           if($data['countlike']=="")
           {
           
              $data['countlike']=0;
           }
              $data['countlike']=intval($data['countlike']);
           return     $data['countlike'];
           
           }
           
           function countcomment($productid)
           {
           
           $sql="SELECT
                    count(tb_plugins_comment_value.comvid) as countlike
                    FROM
                    tb_plugins_comment_value
                    where tb_plugins_comment_value.productid=".$productid." and tb_plugins_comment_value.status=1 ";
           
           $data=$this->db->db_set_1recordrow($sql); 
           if($data['countlike']=="")
           {
           
              $data['countlike']=0;
           }
              $data['countlike']=intval($data['countlike']);
           return     $data['countlike'];
           
           }
           function checkuserfav($productid,$oauth="")
           {
            $userdata=$this->getuserbyoauth($oauth);
            if($userdata['userid'])
            {
            $sql="SELECT
                    tb_fav.favid,tb_fav.status
                    FROM
                    tb_fav
                    INNER JOIN tb_user ON tb_fav.createby = tb_user.userid
                    where tb_fav.productid=".$productid." and tb_user.oauth='".$oauth."' ";
           
           $data=$this->db->db_set_1recordrow($sql);
           if($data['favid'])
           {
             if($data['status']==2)
           {
             return   true;
           }else   if($data['status']==1) 
           {
             return   false;
           
           }
           
           }else
           {
             
             return   false;
           
           } 
            
            
            }else
            {
            
               return   false;
            
            }
           
           
           }
           function favfunction($productid,$oauth)
           {
            $userdata=$this->getuserbyoauth($oauth);
            if($userdata['userid'])
            {
           $sql="SELECT
                    tb_fav.favid,tb_fav.status
                    FROM
                    tb_fav
                    INNER JOIN tb_user ON tb_fav.createby = tb_user.userid
                    where tb_fav.productid=".$productid." and tb_user.oauth='".$oauth."' ";
           
           $data=$this->db->db_set_1recordrow($sql);  
           $arraydata=array(); 
           $arraydata['updateby']=$userdata['userid'];
            
           $arraydata['updatedate']=date("Y-m-d H:i:s"); 
           
           if($data['favid'])
           {
           
           if($data['status']==1)
           {
           $arraydata['status']=2;
           $this->db->db_set($arraydata,'tb_fav',' favid='.$data['favid']); 
           }else
           {
           
          $arraydata['status']=1;
          $this->db->db_set($arraydata,'tb_fav',' favid='.$data['favid']);  
           
           }
           
           return true;
           
           
           }else
           {
           
           
           
           
             $arraydata['status']=2;
             $arraydata['productid']=$productid;
             $arraydata['createdate']=date("Y-m-d H:i:s");
             $arraydata['createby']=$userdata['userid'];
             $this->db->db_set($arraydata,'tb_fav');  
             $favid=$this->db->db_get_last_number();
           
           $sql="select tb_product.productid,tb_product.title,tb_product.createby from tb_product   where tb_product.productid=".$productid;
           $dataproduct=$this->db->db_set_1recordrow($sql);  
           $userid=$dataproduct['createby']; 
           $arraydataset['userid']=$userid;
           $arraydataset['createby']=$userdata['userid'];
           $arraydataset['conid']=3;
           $arraydataset['favid']=$favid;
           $notiid[$userid]=$this->savenotificationlist($arraydataset);
            
           $msgto=$userdata['displayname'].' '.$this->getconditionmsgbyid(3).' '.$dataproduct['title'];
           $arraydatanow[]=$userid;
           $this->sendtonotification($arraydatanow,$msgto,$notiid);
           $this->savegamenictaionbygxcid($userdata['userid'],1);
        //   $this->savescoredata($userdata['userid'],1);
             
             return true;
             
             
           
            
          
           
           
           }
           
           
           
            }else
            {
             return false;  
            
            }
           
           }
           function savefile($name,$filename,$path,$conid="",$cache=1,$fileid="")
           {
              $newpath=str_replace(rootpath.'/','',$path);
              $newpath=str_replace(imgpath.'/','',$newpath);
              $newpath=str_replace(imginfo.'/','',$newpath);
              
              
           $exitfile= strtolower(array_pop(explode('.',$filename)));
           if($conid)
           {
           $arraydataset['conid']=$conid;
           
           }else
           {
           
           $arraydataset['conid']=$this->getconditionbytype($exitfile);
           
           }
           if($cache)
           {
           
           $arraydataset['cache']=$cache;
           
           }else
           {
           
           $arraydataset['cache']=0;
           }
           $arraydataset['size']=filesize($path);
           $arraydataset['path']=$newpath;
           $arraydataset['name']=$name;
           $arraydataset['filename']=$filename;
           
           $arraydataset['createby']=$this->userdata['userid'];
           $arraydataset['createdate']=date("Y-m-d H:i:s");
           
           if($fileid)
           {
           $this->db->db_set($arraydataset,'tb_file',' fileid='.$fileid);
           return $fileid;
           }else
           {
           
           $this->db->db_set($arraydataset,'tb_file');
           $fileid=$this->db->db_get_last_number();
            return $fileid;
           }
           
           
           
           
           
           }
           
           function saveregister($dataArray=array(),$save=0)
           {
           if(count($dataArray))
           {
           if($dataArray['userid'])
           {
           $userid=$dataArray['userid'];
           unset($dataArray['userid']);
           $this->db->db_set($dataArray,"tb_user",' userid='.$userid);
           return $userid;
           }else if($dataArray['oauth']&&$save==0)
           {
           
           $oauth=$dataArray['oauth'];
           unset($dataArray['oauth']);
           
           
           $this->db->db_set($dataArray,"tb_user",' oauth="'.$oauth.'"');
           
           return $oauth;
           
           }else
           {
           $dataArray['createdate']=date("Y-m-d H:i:s");
           $this->db->db_set($dataArray,"tb_user");
           $userid=$this->db->db_get_last_number();
           return $userid;
           }
           
           
           }
           
           }
           
           function tranferdatato($fuserid,$tuserid)
           {
           
           $dataset['createby']=$tuserid;
           $this->db->db_set($dataset,'tb_fav','createby='.$fuserid);
           
           $dataset=array();

           
           $dataset['createby']=$tuserid;
           $this->db->db_set($dataset,'tb_file','createby='.$fuserid);
           
           
           
           


           
           $sql="delete from tb_follow where userid=$fuserid and createby=$tuserid";
           $this->db->db_delete($sql);
           
           
           $sql="delete from tb_follow where userid=$tuserid and createby=$fuserid";
           $this->db->db_delete($sql);
           
             
             $dataset=array();
             $dataset['createby']=$tuserid;
             $this->db->db_set($dataset,'tb_follow','createby='.$fuserid);
             
             $dataset=array();
             $dataset['userid']=$tuserid;
             $this->db->db_set($dataset,'tb_follow','userid='.$fuserid);
              
           
             $dataset=array();
             $dataset['createby']=$tuserid;
             $this->db->db_set($dataset,'tb_img','createby='.$fuserid);
             
             $dataset=array();
             $dataset['createby']=$tuserid;
             $this->db->db_set($dataset,'tb_like','createby='.$fuserid);
             
             
             
             
             $sql="delete from tb_msg where userid=$fuserid and createby=$tuserid";
             $this->db->db_delete($sql);
           
           
            $sql="delete from tb_msg where userid=$tuserid and createby=$fuserid";
            $this->db->db_delete($sql);
             
             $dataset=array();
             $dataset['createby']=$tuserid;
             $this->db->db_set($dataset,'tb_msg','createby='.$fuserid);
             
             
             $dataset=array();
             $dataset['userid']=$tuserid;
             $this->db->db_set($dataset,'tb_msg','userid='.$fuserid);
             
             
             $sql='select * from tb_msg_list where userids like "%|'.$fuserid.'|%"';
             $arraymsglist=$this->db->db_set_recordset($sql);
             if(count($arraymsglist))
             {
             
             foreach($arraymsglist as $valuemsglist)
             {
             
             $dataset=array();
             $dataset['userids']=str_replace('|'.$fuserid.'|','|'.$tuserid.'|',$valuemsglist['userids']);
             $this->db->db_set($dataset,'tb_msg_list','msglid='.$valuemsglist['msglid']);
             
             
             
             }
             }
             
             
             $sql="delete from tb_notification where userid=$fuserid and createby=$tuserid";
             $this->db->db_delete($sql);
           
           
            $sql="delete from tb_notification where userid=$tuserid and createby=$fuserid";
            $this->db->db_delete($sql);
            
            $dataset=array();
             $dataset['createby']=$tuserid;
             $this->db->db_set($dataset,'tb_notification','createby='.$fuserid);
             
             $dataset=array();
             $dataset['userid']=$tuserid;
             $this->db->db_set($dataset,'tb_notification','userid='.$fuserid);
             
             
             
             $dataset=array();
             $dataset['createby']=$tuserid;
             $this->db->db_set($dataset,'tb_notify','createby='.$fuserid);
             
             
             $dataset=array();
             $dataset['createby']=$tuserid;
             $this->db->db_set($dataset,'tb_plugins_comment_value','createby='.$fuserid);
             
             
             $dataset=array();
             $dataset['createby']=$tuserid;
             $this->db->db_set($dataset,'tb_plugins_poll_value','createby='.$fuserid);
             
             
             $dataset=array();
             $dataset['createby']=$tuserid;
             $this->db->db_set($dataset,'tb_plugins_questionnaire_value','createby='.$fuserid);
             
             
             $dataset=array();
             $dataset['createby']=$tuserid;
             $this->db->db_set($dataset,'tb_plugins_reservationregister_value','createby='.$fuserid);
             
             
             $dataset=array();
             $dataset['userid']=$tuserid;
             $this->db->db_set($dataset,'tb_plugins_reservationregister_value','userid='.$fuserid);
             
             
             
             
             
             $dataset=array();
             $dataset['createby']=$tuserid;
             $this->db->db_set($dataset,'tb_plugins_reservationregistercanon_value','createby='.$fuserid);
             
             
             $dataset=array();
             $dataset['userid']=$tuserid;
             $this->db->db_set($dataset,'tb_plugins_reservationregistercanon_value','userid='.$fuserid);
             
             
             $dataset=array();
             $dataset['createby']=$tuserid;
             $this->db->db_set($dataset,'tb_plugins_reservation_value','createby='.$fuserid);
             
             
             $dataset=array();
             $dataset['userid']=$tuserid;
             $this->db->db_set($dataset,'tb_plugins_reservation_value','userid='.$fuserid);
             
             
             $dataset=array();
             $dataset['createby']=$tuserid;
             $this->db->db_set($dataset,'tb_product','createby='.$fuserid);
             
             $dataset=array();
             $dataset['userid']=$tuserid;
             $this->db->db_set($dataset,'tb_read_notify','userid='.$fuserid);
             
             
             $dataset=array();
             $dataset['createby']=$tuserid;
             $this->db->db_set($dataset,'tb_serial','createby='.$fuserid);
             
             $dataset=array();
             $dataset['createby']=$tuserid;
             $this->db->db_set($dataset,'tb_share_stat','createby='.$fuserid);
             
             
             $dataset=array();
             $dataset['createby']=$tuserid;
             $this->db->db_set($dataset,'tb_tag','createby='.$fuserid);
             
             
             $dataset=array();
             $dataset['userid']=$tuserid;
             $this->db->db_set($dataset,'tb_token','userid='.$fuserid);
             
             
             $dataset=array();
             $dataset['userid']=$tuserid;
             $this->db->db_set($dataset,'tb_token','userid='.$fuserid);
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
           
           
           }
           function tranferuserto($fuserid,$tuserid)
           {
           $sql='select * from tb_user where userid='.$fuserid;
           $arrayuserf=$this->db->db_set_1recordrow($sql);
           
           
           $sql='select * from tb_user where userid='.$tuserid;
           $arrayusert=$this->db->db_set_1recordrow($sql);
           
           $arraynew=array();
           if(count($arrayuserf))
           {
           foreach($arrayuserf as $keyf => $valuef)
           {
           if(trim($valuef)&&trim($valuef)!='0')
           {
           $arraynew[$keyf]=$valuef;
           
           }else
           {
           
           $arraynew[$keyf]=$arrayusert[$keyf];
           
           }
           
           }
           
           }
           
           unset($arraynew['userid']);
           $arraynew['syncfacebook']=1;
           $arraynew['syncuser']=1;
           $arraynew['oauth']=$arrayusert['oauth'];
           $time=0;
           if($_COOKIE['timelimit'])
           {
           $time=intval($_COOKIE['timelimit']);
           }
           $domain='';
                      if(NameDmconnex=="Canonlife"){
                      $url='http://'.$_SERVER['HTTP_HOST'];
                      $domain='.'.get_domain($url);
                      }
           setcookie("username",$arraynew['username'], $time, "/",$domain);
           
           
           $this->db->db_set($arraynew,'tb_user','userid='.$tuserid);
           
           $sql='delete from tb_user where userid='.$fuserid;
           $this->db->db_delete($sql);
           
           
           }
           
           function getuserbyoauth($oauth,$select="")
           {
           
           $sql="select username,displayname,oauth,imgmid,simgmid,userid,tb_user.status,tb_user.roleid $select from tb_user where oauth='".$oauth."'";
           $arrayuser=$this->db->db_set_recordset($sql);
           return $arrayuser[0];
           
           }
           
           function getuserbyusername($username,$select="")
           {
           
           $sql="select username,displayname,oauth,imgmid,simgmid,userid,tb_user.status,tb_user.roleid $select from tb_user where username='".$username."'";
           $arrayuser=$this->db->db_set_recordset($sql);
           return $arrayuser[0];
           
           }
           function getuserbyuserid($userid,$select="")
           {
           
           $sql="select username,displayname,oauth,imgmid,simgmid,userid,tb_user.status,tb_user.roleid $select from tb_user where userid='".$userid."'";
           $arrayuser=$this->db->db_set_recordset($sql);
           return $arrayuser[0];
           
           }
           
           function getimagecloudbyuserid($userid,$page=1)
           {
           $page=(($page-1)*12);
           $sql="select * from tb_img where conid=6 and createby=".$userid." and cache=1 and width>0 order by updatedate desc  limit $page,12 "; 
           $arrayimage=$this->db->db_set_recordset($sql);
           $arraynewdata=array();
//           echo "<pre>";
//           print_r($arrayimage);
//           echo "</pre>;";
//           exit;
           if(count($arrayimage))
           {
           foreach($arrayimage as $valueimage)
           {
           

           
          
           $valueimage['thumb']=$this->getimagebyimgid($valueimage['imgid'],14,160,160);
          
           
           
           $arraynewdata[]=$valueimage;
           
           }
           
           
           }
           return $arraynewdata;    
           
           }
           
           function getimagecloudbysystem($page=1)
           {
           $page=(($page-1)*12);
           $sql="select * from tb_img where conid=6  and cache=0 and system=1 and width>0 order by updatedate desc  limit $page,12 "; 
           $arrayimage=$this->db->db_set_recordset($sql);
           $arraynewdata=array();
//           echo "<pre>";
//           print_r($arrayimage);
//           echo "</pre>;";
//           exit;
           if(count($arrayimage))
           {
           foreach($arrayimage as $valueimage)
           {
           

           
          
           $valueimage['thumb']=$this->getimagebyimgid($valueimage['imgid'],14,160,160);
          
           
           
           $arraynewdata[]=$valueimage;
           
           }
           
           
           }
           return $arraynewdata;    
           
           }
           
           function swicthpathimage($imgmid,$productid,$thumb=0)
           {
           
           $sql="select * FROM `tb_img` where imgmid=".$imgmid;
           $arrayimg=$this->db->db_set_1recordrow($sql);
           
           if($arrayimg['imgmid'])
           {
           if($arrayimg['system']==1||$arrayimg['productid']==0)
           {
             $arrayimg['system']=0;
             unset($arrayimg['imgmid']);
             $path=$arrayimg['path'];
             if(is_file(rootpath.'/'.$path)&&!is_file(imgpath.'/'.$productid.'/'.$arrayimg['name']))
             {
             if(copy(rootpath.'/'.$path,imgpath.'/'.$productid.'/'.$arrayimg['name']))
             {
             @chmod(imgpath.'/'.$productid,0777);
             
             
              
             }
             }
             $arrayimg['path']=str_replace(rootpath.'/','',imgpath.'/'.$productid.'/'.$arrayimg['name']);
             $arrayimg['cache']=0;
             $arrayimg['productid']=$productid;
             $arrayimg['thumb']=$thumb;
             $arrayimg['updateby']=$this->userdata['userid'];
             $arrayimg['updatedate']=date("Y-m-d H:i:s");
             
             
             
             
             $this->db->db_set($arrayimg,'tb_img');
             $imgmid=$this->db->db_get_last_number();
             return $imgmid;
             
             
             
           
           
           }
           else 
           {
           
           return $imgmid;
           
           }
           
           }
           else
           {
           
           return $imgmid;
           
           }
           
           
           
           }
           
           function saveplugins($plugins,$productid)
           {
           

           
             if(count($plugins))
             {
             
             $sql="select plugid from tb_plugins_relate where productid=".$productid;
             $arrayrelete=$this->db->db_set_recordset($sql);
             $sql="delete from tb_plugins_relate where productid=".$productid;
             $this->db->db_delete($sql);
             
             
             if(count($arrayrelete))
             {
             foreach($arrayrelete as $valuerelete)
             {
             if($valuerelete['plugid']&&intval($valuerelete['plugid'])!=30)
             {
             $sql="select name from tb_plugins where plugid=".$valuerelete['plugid'];
             $arrayplugin2=$this->db->db_set_1recordrow($sql);
             if($arrayplugin2['name'])
             {
             if($arrayplugin2['name']=='bookupload')
             {
             $arrayplugin2['name']='upload_book';
             }
             $sql="delete from tb_plugins_".$arrayplugin2['name']." where productid=".$productid;
             $this->db->db_delete($sql);
             
             
             }
             
             
             }
             
             }
             
             }
                          $rowsort=1;
             foreach($plugins as $valueplugin)
             {

             if($valueplugin['plugid']&&intval($valueplugin['plugid'])!=30)
             {
             

             
             
             
             $arraydataset=array();
             $arraydataset['plugid']=intval($valueplugin['plugid']);
             $arraydataset['productid']=$productid;
             $arraydataset['sort']=$rowsort++;
             $this->db->db_set($arraydataset,'tb_plugins_relate');
             $plugreid=$this->db->db_get_last_number();
             //echo $valueplugin['plugid']."\n";
             $sql="select name from tb_plugins where plugid=".$valueplugin['plugid'];
             $arrayplugin=$this->db->db_set_1recordrow($sql);
             $name=$arrayplugin['name'];
             eval("\$obj = new Plugins_".ucfirst($name).'($this->db);');
             unset($valueplugin['plugid']);
             $obj->saveplugin($valueplugin,$productid,$plugreid);
             
             
             }
             
             
             }
             
             
             }
           
           
           
           }
           
           function getplugins($productid)
           {
                
               
               
              $sql=" SELECT * FROM `tb_plugins_relate` where productid=".$productid.' order by sort asc';
              $arrayplugins=$this->db->db_set_recordset($sql);
              $arraynewdata=array();
              if(count($arrayplugins))
              {
              
              foreach($arrayplugins as $valueplugin)
              {
                 $sql="select name from tb_plugins where plugid=".$valueplugin['plugid'];
                 $arrayplugin=$this->db->db_set_1recordrow($sql);
                 $name=$arrayplugin['name'];

                 eval("\$obj = new Plugins_".ucfirst($name).'($this->db);');
                $arrayplugins=array();
                $arrayplugins2=$obj->getplugin($valueplugin['plugreid']);
                $arrayplugins['plugid']=$valueplugin['plugid'];
                $arrayplugins['plugname']=$arrayplugin['name'];

                $newarrayplugins=array_merge($arrayplugins,$arrayplugins2);
                
                $arraynewdata[]=$newarrayplugins;
              
              }
              
              }
              
              return $arraynewdata;
           
           
           }
                            
           function savetag($tagsystem,$taguser,$productid,$fid)
           {
            $arraytag=array();
            if(count($tagsystem)&&$tagsystem)
            {

            $strtag=join("','",$tagsystem);
            $sql="select tagid from tb_tag where name IN ('".$strtag."')";
            $arraytag2=$this->db->db_set_recordset($sql);
            if(count($arraytag2))
            {
            foreach($arraytag2 as $valuetag)
            {
            $arraytag[]=$valuetag['tagid'];
            
            }
            
            }
            }
            
            if($taguser)
            {
              $arraytaguser=explode("#",$taguser);
              if(count($arraytaguser)>1)
              {
              array_shift($arraytaguser);
              
              }
              
             
             if(count($arraytaguser)) 
             {
             foreach($arraytaguser as $valuetaguser)
             {
             if(trim($valuetaguser)!="")
             {
             $valuetaguser=trim($valuetaguser);
             getFilesFromDirMuti(includepath,$arraynow);
             
             
             $sql="select tagid from tb_tag where name = '".mysql_real_escape_string($valuetaguser)."' ";
             $arraytag2=$this->db->db_set_1recordrow($sql);
            if($arraytag2['tagid'])
            {
            $arraytag[]=$arraytag2['tagid'];
            }
            else
            {
            
            if(array_search_r_like($valuetaguser, $arraynow)||array_search_r_like($valuetaguser, $this->info['configall']['feature']))
                {
                $valuetaguser=$valuetaguser.'1';
                
                }
                
                
                $sql="select tagid from tb_tag where name = '".mysql_real_escape_string($valuetaguser)."' ";
             $arraytag2=$this->db->db_set_1recordrow($sql);
              if($arraytag2['tagid'])
            {
            $arraytag[]=$arraytag2['tagid'];
            }
            else
            {
            
            
            $arrayset=array();
            $arrayset['name']=$valuetaguser;
            $arrayset['fid']=$fid;
            
            $arrayset['createby']=$this->userdata['userid'];
            $arrayset['createdate']=date("Y-m-d H:i:s");
            $this->db->db_set($arrayset,'tb_tag');
            $arraytag[]=$this->db->db_get_last_number();
            }
            
            
            
            }
            
            

            
             }
            
             }
            
             }
            
            
            }
            $arraytag=array_unique($arraytag);
            if(count($arraytag))
            {
            $sql="delete from tb_relate_tag where productid=".$productid;
            $this->db->db_delete($sql);
            foreach($arraytag as $valuetag)
            {
            $arrayset=array();
            $arrayset['tagid']=$valuetag;
            $arrayset['productid']=$productid;
            $arrayset['createby']=$this->userdata['userid'];
            $arrayset['createdate']=date("Y-m-d H:i:s");
            $this->db->db_set($arrayset,'tb_relate_tag');
            
            }
            
            
            }
            
        
           
           
           }
                  
           function checkusername($username)
           {
           //
           
            if(strlen($username)>3)
            {
            if((bool)preg_match('/^[a-z\d_]{4,20}$/i', $username))
            {
            getFilesFromDirMuti(includepath,$arraynow);
            
            
//            echo "<pre>";
//            print_r($this->info['configall']['feature']);
//            echo "</pre>;";



            if(array_search_r_like($username, $arraynow)||array_search_r_like($username, $this->info['configall']['feature']))
            {
            //echo $username;
            
            return 6;
            
            }else
            {

              $sql="select userid from tb_user where username='".$username."'";
              
              $arrayuser=$this->db->db_set_recordset($sql);
              
              
              
              if($arrayuser[0]['userid'])
              {
              
              return 6;
              }else
              {
              
              return 1;
              }
           
            
            
            }
            }else
            {
            
            return 7;
            }
            }else
            {
            
            return 29;
            }
            
            
            
           
         //  $sql="select userid from tb_user where username='".$username."'";
          // $arrayuser=$this->db->db_set_recordset($sql);
           
           
           
           }
           
           function checkemail($email)
           {
           if( ( (bool)(preg_match("/^([a-z0-9+_-]+)(.[a-z0-9+_-]+)*@([a-z0-9-]+.)+[a-z]{2,6}$/ix",
  $email))  ) && ((bool)checkdnsrr(preg_replace('/^[^@]++@/', '', $email), 'MX') ) )
              {
              $sql="select userid from tb_user where email='".$email."'";
              $arrayuser=$this->db->db_set_recordset($sql);
              
               if($arrayuser[0]['userid'])
              {
              
              return 8;
              }else
              {
              
              return 1;
              }
              
              }else
              {
              return 9;
              
              }
           
           }
           
           function cropimage($source,$widthnew,$heightnew,$newsource="")
           {
           if (!class_exists('PhpThumbFactory')) { /*code*/ 
           require_once pluginpath.'/resize/ThumbLib.inc.php';
           }

           if(is_file($source)||(filter_var($source, FILTER_VALIDATE_URL) !== FALSE) )
           {

           $thumb = PhpThumbFactory::create($source);
           $thumb->setOptions(array('bgcolor'=> array(255, 255, 255)));
           
           list($width, $height, $type, $attr) = getimagesize($source);

           
           $arraypic=explode("/",$source);
   
           $namepic=$arraypic[count($arraypic)-1];
           list($namefile,$exitfile)=explode(".",$namepic);
           $newnamepic=$namefile.'-'.$widthnew.'x'.$heightnew.'.'.$exitfile;
           $newpath=str_replace($namepic,$newnamepic,$source);
            
           
            if(($widthnew&&$heightnew==0)||($widthnew==0&&$heightnew))
            {
            

            if($widthnew==0)
            {
            $widthnow= intval(($heightnew*$width)/($height));
            $heightnow=$heightnew;
            }else if($heightnew==0)
            {
            $widthnow=$widthnew;
            if($width>$widthnew)
            {
            $heightnow=intval(($widthnew*$height)/($width));
            }else
            {
            $heightnow=$height;
            
            }
            
            
            
            }
           // echo $widthnow."<br>";
          //  echo $heightnow."<br>";
            
            $thumb->resize($widthnow, $heightnow,true);
            }
            else if ($width <$widthnew||$height<$heightnew)
            {

            if($width <$widthnew)
            {
            
            $thumb->resize($widthnew, $height,true);
            
            }else
            {
            
            $thumb->resize($width, $heightnew,true);
            }
            

            }
            else
            {
            
            $thumb->adaptiveResize($widthnew, $heightnew);
            }
     
             if($newsource)
             {
             $newpath=$newsource;
             }
              
             
             $thumb->save($newpath,'JPG');
            chmod($newpath,0777); 
           
           
           
              }
           
           
           
           }
           
           function getconditionbysize($width,$height)
           {
            $sql="select conid  from tb_condition where width=".$width." and height=".$height;
            $arrayconid=$this->db->db_set_recordset($sql);
            if($arrayconid[0]['conid'])
            {
            return $arrayconid[0]['conid'];
            }else
            {
           // 
//            $dataArray['width']=$width;
//            $dataArray['height']=$height;
//            $dataArray['msg']=$width.'x'.$height;
//            $dataArray['name']=$width.'x'.$height;
//            $this->db->db_set($dataArray,"tb_condition");
//            $conid=$this->db->db_get_last_number();
            return 0;
            
            }
           
           
           }
           
           function gettagbyproductid($productid)
           {
           
           $sql="SELECT
           tb_tag.`name`,
           tb_tag.system,
           tb_tag.tagid
           FROM
           tb_relate_tag
           INNER JOIN tb_tag ON tb_tag.tagid = tb_relate_tag.tagid
           where tb_relate_tag.productid=".$productid;
           
           $arraytag=$this->db->db_set_recordset($sql);
           
           
           return $arraytag;
           
           }
           
           function gettagbytaguser($tagarray2,$createby)
           {
           if(count($tagarray2))
           {
           $tagarray=array();
           foreach($tagarray2 as $valuetag)
           {
           
           $tagarray[]=$valuetag['tagid'];
           
           
           
           }
           
           $sql='SELECT
tb_user.imgmid,
tb_user.simgmid,
tb_user.username,
tb_user.displayname
FROM
tb_relate_tag
INNER JOIN tb_product ON tb_product.productid = tb_relate_tag.productid
INNER JOIN tb_user ON tb_user.userid = tb_product.createby

where tb_relate_tag.tagid IN ('.join(',',$tagarray).') and tb_product.createby!='.$createby.' GROUP BY tb_product.createby limit 0,20';

            


            $arraydata=$this->db->db_set_recordset($sql);
            $rowdata=0;
            if(count($arraydata))
            {
            foreach($arraydata as $valuedata)
            {
            
            $arraydata[$rowdata]['img']=$this->getimagebyimgmid($valuedata['imgmid']);
            $arraydata[$rowdata]['simg']=$this->getimagebyimgmid($valuedata['simgmid']);
            $rowdata++;
            
            
            }
            
            }

            
           return $arraydata;
           
           }else
           {
           
           return array();
           }
           
           }
           
           function gettagidbytagname($tagname)
           {
           $sql="SELECT
           tb_tag.tagid
           FROM
           tb_tag
           where tb_tag.`name`='".$tagname."'";

           $arraytag=$this->db->db_set_1recordrow($sql);
           return $arraytag['tagid'];
           
           }
           
           function getserialbyuserid($userid)
           {
           
           $sql="SHOW TABLES LIKE 'tb_serial'";
           $arraycheck=$this->db->db_set_1recordrow($sql);
           if(count($arraycheck))
                 {
                 
                 $sql='select *  FROM `tb_serial` where createby='.$userid.' order by createdate desc';
                 $arraycheck=$this->db->db_set_1recordrow($sql);
                 
                return $arraycheck['serial'];
                 
                 }else
                {
                return '';
                
                
                }
           
           
           
           
           
           
           }
           
           function getallserialbyuserid($userid)
           {
           
           $sql="SHOW TABLES LIKE 'tb_serial'";
           $arraycheck=$this->db->db_set_1recordrow($sql);
           if(count($arraycheck))
                 {
                 
                 $sql='select *  FROM `tb_serial` where createby='.$userid.' order by createdate desc';
                 $arraycheck=$this->db->db_set_recordset($sql);
                 
                return $arraycheck;
                 
                 }else
                {
                return '';
                
                
                }
           
           
           
           
           
           
           }
           
           function gotocheck($serial,$getstatus=0)
           {
                $url="http://goto.canon.co.th/chkserial/chkserial.php";
               // $url="http://www.canonlife.com/ajax/testdatapost";
                
                $post['SerialNumber']=$serial;
                
              //  $post['SerialNumber']='canon eos 5D mark I';
                $post['CHKUSER']=true;
                $useragent = "Opera/9.80 (J2ME/MIDP; Opera Mini/4.2.14912/870; U; id) Presto/2.4.15";
                $useragent = "";
                $header = array(
                "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
                "Accept-Language: en-us,en;q=0.5",
                "Connection: keep-alive",
                "Cache-Control: no-cache",
                "Content-Type: application/x-www-form-urlencoded; charset=UTF-8",
                "Pragma: no-cache",
                );
                
                 
                 $ch = curl_init ("");
                curl_setopt ($ch, CURLOPT_URL, $url);
                curl_setopt ($ch, CURLOPT_USERAGENT, $useragent); // set user agent
                curl_setopt($ch, CURLOPT_TIMEOUT, 10);
                curl_setopt($ch, CURLOPT_AUTOREFERER, true);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies2.txt");
                curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies2.txt");
               // curl_setopt($ch, CURLOPT_HEADER, 0);
               // curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
                curl_setopt($ch, CURLOPT_VERBOSE, 0);
                //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
                curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
                
                curl_setopt($ch, CURLOPT_POST, 1); 
                curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
                
                $output = curl_exec ($ch);

                curl_close($ch);

                //$returndata=FetchContent($url,'','','',$post);
              // $returndata= FetchContent($url,'','C:\Documents and Settings\Administrator\Local Settings\Temporary Internet Files\cookies.txt',$url,$post,1);
                
                $xml = simplexml_load_string($output);
         //       $data=object_to_array($xml);
                if($getstatus)
                {
;
              $data=XML2Array($xml->ModelName);
                return $data['ModelName'];
                
                }else
                {
                
                
                
                return   intval($xml->Status);
                }

           
           
           }
           
             
           function gotocheckcanonserial($serial)
           {
                $url="http://goto.canon.co.th/chkserial/chkserial.php";
               // $url="http://www.canonlife.com/ajax/testdatapost";
                
                $post['SerialNumber']=$serial;
                
              //  $post['SerialNumber']='canon eos 5D mark I';
                $post['CHKUSER']=true;
                $useragent = "Opera/9.80 (J2ME/MIDP; Opera Mini/4.2.14912/870; U; id) Presto/2.4.15";
                $useragent = "";
                $header = array(
                "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
                "Accept-Language: en-us,en;q=0.5",
                "Connection: keep-alive",
                "Cache-Control: no-cache",
                "Content-Type: application/x-www-form-urlencoded; charset=UTF-8",
                "Pragma: no-cache",
                );
                
                 
                 $ch = curl_init ("");
                curl_setopt ($ch, CURLOPT_URL, $url);
                curl_setopt ($ch, CURLOPT_USERAGENT, $useragent); // set user agent
                curl_setopt($ch, CURLOPT_TIMEOUT, 10);
                curl_setopt($ch, CURLOPT_AUTOREFERER, true);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies2.txt");
                curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies2.txt");
               // curl_setopt($ch, CURLOPT_HEADER, 0);
               // curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
                curl_setopt($ch, CURLOPT_VERBOSE, 0);
                //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
                curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
                
                curl_setopt($ch, CURLOPT_POST, 1); 
                curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
                
                $output = curl_exec ($ch);

                curl_close($ch);

                //$returndata=FetchContent($url,'','','',$post);
              // $returndata= FetchContent($url,'','C:\Documents and Settings\Administrator\Local Settings\Temporary Internet Files\cookies.txt',$url,$post,1);
                
                $xml = simplexml_load_string($output);
         //       $data=object_to_array($xml);
                
;
              $data=XML2Array($xml);
               
               return $data;

           
           
           }
           
           
           
           function checkserial($serial)
           {
           
           
           if(NameDmconnex=="Canonlife"){ 
           
           
           $status=$this->gotocheck($serial);
           
           if($status)
           {
         
           }else
           {
           
           return 35;
           
           }
           
           
           
           
           }
           
           $sql='SELECT * FROM `tb_serial` where  serial="'.$serial.'"';
           $arrayserial=$this->db->db_set_1recordrow($sql);
           if($arrayserial['serialid'])
           {
           
           
           return 36;
           
           }else
           {
           
           
           
           return true;
           
           }
           
          
           
           
           
           
           
           
           
           }
           
           function getdataposcheckbydate($date1,$date2)
           {
           
            $strwhere='  tb_product_order.createdate BETWEEN "'.$date1.'" AND "'.$date2.'" ';
                $sql='
SELECT
IF(sum(tb_product_suborder.price*tb_product_suborder.count) IS NULL ,0,sum(tb_product_suborder.price*tb_product_suborder.count)) as sumall
FROM
tb_product_order
INNER JOIN tb_product_suborder ON tb_product_order.orderid = tb_product_suborder.orderid
where  price !=0 and '.$strwhere;



                $checkcount=$this->db->db_set_1recordrow($sql);
                
                
                $arraydatecheck['col']['summary']=$checkcount['sumall'];
                
                
                
                $sql='
SELECT
IF(sum(tb_product_suborder.discount*tb_product_suborder.count) IS NULL ,0,sum(tb_product_suborder.discount*tb_product_suborder.count)) as sumall
FROM
tb_product_order
INNER JOIN tb_product_suborder ON tb_product_order.orderid = tb_product_suborder.orderid
where  discount !=0 and'.$strwhere;



                $checkcount=$this->db->db_set_1recordrow($sql);
                
                
                $arraydatecheck['col']['discount']=$checkcount['sumall'];
                
                
                
                $arraydatecheck['col']['total']=intval($arraydatecheck['col']['summary'])-intval($checkcount['sumall']);
                
                
                
                $sql='SELECT
sum(IF(tb_plugins_price.oprice = 0,tb_plugins_price.price,tb_plugins_price.oprice)*tb_product_suborder.count) as opricedata
FROM
tb_product_order
INNER JOIN tb_product_suborder ON tb_product_order.orderid = tb_product_suborder.orderid
INNER JOIN tb_plugins_price ON tb_product_suborder.productid = tb_plugins_price.productid
where tb_product_suborder.price !=0 and '.$strwhere;

                

                $checkcount2=$this->db->db_set_1recordrow($sql);
                if($checkcount2['opricedata'])
                {
                $arraydatecheck['col']['oprice']=$checkcount2['opricedata'];
                }else
                {
                $arraydatecheck['col']['oprice']="0";
                }
                
              //  $arraydatecheck['col']['osql']=$sql;
                
                
                $arraydatecheck['col']['totalall']=$arraydatecheck['col']['total']-intval($arraydatecheck['col']['oprice']);
                
                
                
                return $arraydatecheck['col'];
           
           
           }
           
           function gettagbyfid($fid,$system=1,$swap=0)
           {
           
           $sql=
           '
           SELECT * from (
           SELECT
           tb_tag.tagid,
           tb_tag.`name`,tb_tag.createdate,tb_tag_show.stagid
           FROM
           tb_tag_show
           INNER JOIN tb_tag ON tb_tag.tagid = tb_tag_show.tagid
           where tb_tag_show.fid='.$fid.'
           union
           select tagid,name,tb_tag.createdate,1 as stagid  from tb_tag where tb_tag.all=1 and system='.$system.'
           ) tb_tag order by tb_tag.stagid desc
           
           
           
           ';
           if($swap)
           {
           $arraytag=$this->db->db_set_recordset($sql);
           }else
           {
           $arraytag=$this->db->db_set_recordrow($sql);
           
           }
           
           return $arraytag;
           }
           
           
           function getcreditdata($userid)
           {
           $sql='select  * from tb_pay_credit where userid='.$userid;
           $arraypay=$this->db->db_set_1recordrow($sql);
           if($arraypay['creditid'])
           {
           $credit=intval($arraypay['credit']);
           
           }else
           {
           
           $credit=0;
           
           }
           
           return $credit;
           
           
           }
           
           function gettagpoppular($fid=0)
           {
           $where="";
           if($fid)
           {
           $where=" and tb_product.fid=".$fid;
           
           }
           
           $sql="SELECT
                tb_relate_tag.tagid,tb_tag.`name`,count(tb_relate_tag.tagid)counttag
                FROM
                tb_relate_tag
                INNER JOIN (select productid from tb_product where tb_product.delete=0 $where) tb_product on tb_relate_tag.productid=tb_product.productid
                INNER JOIN tb_tag on tb_tag.tagid=tb_relate_tag.tagid
                GROUP BY tb_relate_tag.tagid
                ORDER BY counttag desc
                limit 0,30";
                
           $arraydata=$this->db->db_set_recordset($sql);
           
           return $arraydata;
           
           
           }
           
           function gettagsystem()
           {
           $sql="SELECT
tb_tag.tagid,
tb_tag.`name`
FROM
tb_tag
where 
tb_tag.system=1
ORDER BY stagid asc
";
            $arraydata=$this->db->db_set_recordset($sql);
           
           return $arraydata;
           
           }
           
           
           function getconditionbytype($type)
           {
            $type=strtolower($type);
            $sql="select conid  from tb_condition where name='".$type."'";
            $arrayconid=$this->db->db_set_recordset($sql);
            if($arrayconid[0]['conid'])
            {
            return $arrayconid[0]['conid'];
            }else
            {
           

            $dataArray['msg']='type '.$type;
            $dataArray['name']=$type;
            $this->db->db_set($dataArray,"tb_condition");
            $conid=$this->db->db_get_last_number();
            return $conid;
            
            }
           
           
           }
           
           function __destruct() 
           {
           
           if($this->close)
           {
           //echo "close";
           $this->db->closedb(); 
           }
           
           
           //exit;
            
            }
            
            function getcountry($getsql='name',$swap=0)
            {
            $sql="SELECT countryid,$getsql FROM `tb_country`";
            if($swap)
            {
            $arrayrow=$this->db->db_set_recordset($sql);
            }else
            {
            
            $arrayrow=$this->db->db_set_recordrow($sql);
            }
            
            return $arrayrow;
            
            }
            
            function getcountrynamebycoutryid($countryid)
            {
            $sql="SELECT tb_country.name FROM `tb_country` where countryid=$countryid";
            $arrayrow=$this->db->db_set_1recordrow($sql);
            return $arrayrow['name'];
            
            }
            
            function geterror($errorid)
            {
            
               $sql=" select *  from tb_error where code=".$errorid;
               $arrayerror=$this->db->db_set_1recordrow($sql); 
               $arrayerror['code']=$errorid;
               
               return $arrayerror;
            
            }
            function getlangall()
            {
                 //;
                 

                 return $this->info['configall']['lang'];
            
            
            }
            
            function gettemplate()
            {
                 $sql='SELECT
tb_template.tempid,
tb_template.path,
tb_template.img,
tb_template.`name`
FROM
tb_template';

$arrayrow=$this->db->db_set_recordset($sql);


                return          $arrayrow;
            
            }
            
            function getprovince($getsql='proname',$swap=0)
            {
            
            $sql="SELECT proid,$getsql FROM `tb_province`";
            if($swap)
            {
            $arrayrow=$this->db->db_set_recordset($sql);
            }else
            {
            
            $arrayrow=$this->db->db_set_recordrow($sql);
            }
            return $arrayrow;
            
            }
            
            function getprovincebyproid($proid)
            {
            
            $sql="SELECT proname FROM `tb_province` where tb_province.proid=$proid";
            $arrayrow=$this->db->db_set_1recordrow($sql);
            return $arrayrow['proname'];
           // return $arrayrow;
            
            }
            
            function getstatorderbyshopid($shopid)
            {
            $arraydata=array();
            
            $sql='select SUM(tb_product_order.sumall) as sumdata from tb_product_order where tb_product_order.status>1 and tb_product_order.status<4 and tb_product_order.createby='.$shopid;
            
            $arrayrow=$this->db->db_set_1recordrow($sql);
            
            $sumdata=0;
            if($arrayrow['sumdata'])
            {
            $sumdata=intval($arrayrow['sumdata']);
            
            }
            
            $arraydata['benefit']=number_format($sumdata);
            
            
            $sql='select SUM(tb_product_order.point) as pointall from tb_product_order where tb_product_order.status>1 and tb_product_order.status<4 and tb_product_order.createby='.$shopid;
            
            $arrayrow=$this->db->db_set_1recordrow($sql);
            
            $sumdata=0;
            if($arrayrow['pointall'])
            {
            $sumdata=intval($arrayrow['pointall']);
            
            }
            
            $arraydata['paypoint']=number_format($sumdata);
            
            
             $sql='select count(tb_product_order.orderid) as countdata from tb_product_order where tb_product_order.createby='.$shopid;
            
            $arrayrow=$this->db->db_set_1recordrow($sql);
            
            
            $sumdata=0;
            if($arrayrow['countdata'])
            {
            $sumdata=intval($arrayrow['countdata']);
            
            }
            
            $arraydata['countorder']=number_format($sumdata);
            
            $sql='SELECT
SUM(tb_product_suborder.count) countitem
FROM
tb_product_order
INNER JOIN tb_product_suborder ON tb_product_order.orderid = tb_product_suborder.orderid
where tb_product_order.`status`>1 and tb_product_order.`status`<4 and tb_product_suborder.discount=\'0.00\' and tb_product_order.createby='.$shopid;

            $arrayrow=$this->db->db_set_1recordrow($sql);
            
            
             $sumdata=0;
            if($arrayrow['countitem'])
            {
            $sumdata=intval($arrayrow['countitem']);
            
            }
            
            $arraydata['solditem']=number_format($sumdata);
            
            
            
              $sql='SELECT
SUM(tb_product_suborder.count) countitem
FROM
tb_product_order
INNER JOIN tb_product_suborder ON tb_product_order.orderid = tb_product_suborder.orderid
where tb_product_order.`status`>1 and tb_product_order.`status`<4 and tb_product_suborder.discount!=\'0.00\' and tb_product_order.createby='.$shopid;

            $arrayrow=$this->db->db_set_1recordrow($sql);
            
            
             $sumdata=0;
            if($arrayrow['countitem'])
            {
            $sumdata=intval($arrayrow['countitem']);
            
            }
            
            $arraydata['couponitem']=number_format($sumdata);
            
            
            
             $sql='SELECT
SUM(tb_product_suborder.discount) sumdiscount
FROM
tb_product_order
INNER JOIN tb_product_suborder ON tb_product_order.orderid = tb_product_suborder.orderid
where tb_product_order.`status`>1 and tb_product_order.`status`<4 and tb_product_suborder.discount!=\'0.00\' and tb_product_order.createby='.$shopid;

            $arrayrow=$this->db->db_set_1recordrow($sql);
            
            
             $sumdata=0;
            if($arrayrow['sumdiscount'])
            {
            $sumdata=intval($arrayrow['sumdiscount']);
            
            }
            
            $arraydata['couponvalue']=number_format($sumdata);
            
            
            return $arraydata;
            
            
            
            
            
            
            }
            
            function getcurrency()
            {
            $sql="SELECT curid,name FROM `tb_currency`";
            $arrayrow=$this->db->db_set_recordrow($sql);
            return $arrayrow;
            
            }
            
            function getcurrencybycurid($curid)
            {
            $sql="SELECT curid,name FROM `tb_currency` where curid=".$curid;
            $arrayrow=$this->db->db_set_1recordrow($sql);
            return $arrayrow['name'];
            
            }
            
            function gettime($startdate="00:00",$enddate="23:30")
            {
            
            $start =$startdate;
            $end =$enddate;
            $tStart = strtotime($start);
            $tEnd = strtotime($end);
            $tNow = $tStart;
            $arrayselect=array();
            while($tNow <= $tEnd){
                  $arrayselect[date("H:i",$tNow)]= date("H:i",$tNow)."\n";
                  $tNow = strtotime('+30 minutes',$tNow);
                }
                
                return $arrayselect;
            
            }
            
            function getconfig()
            {
            
            
            
            }
            
            function getspacedatabyuserid($userid)
            {
            $sql="select space,roleid from tb_user where tb_user.userid=$userid";
            $arrayspace=$this->db->db_set_1recordrow($sql);
            if(intval($arrayspace['roleid'])>2)
            {
            return      "0";
            
            }else
            {
            return      $arrayspace['space'];
            
            }
            
            
            }
            function getusedspacedatabyuserid($userid)  
            {
              $sql="select sum(tb_img.size) as userspace from tb_img where tb_img.createby=".$userid;
              $arrayspace=$this->db->db_set_1recordrow($sql);
              
          
               return      (($arrayspace['userspace']/(1024))/1024);
            
           
            
            }
            
            function rotateimage($filename)
            {

         

           
                // Open File
                // ---------------------------------------------
               
            
            
try
{   
            $imagick_type = new Imagick();
            $file_to_grab = $filename;
           
            $file_handle_for_viewing_image_file = fopen($file_to_grab, 'a+');
           


            $imagick_type->readImageFile($file_handle_for_viewing_image_file);

           fclose($file_handle_for_viewing_image_file);


           


            $imagick_orientation = $imagick_type->getImageOrientation();
           
            switch($imagick_orientation)
            {
                case '0':
                    $imagick_orientation_evaluated = "Undefined";
                    $degrees=0;
                    break;
               
                case '1':
                    $imagick_orientation_evaluated = "Top-Left";
                    $degrees=0;
                    break;
               
                case '2':
                    $imagick_orientation_evaluated = "Top-Right";
                    $degrees = 0;
                    break;
               
                case '3':
                    $imagick_orientation_evaluated = "Bottom-Right";
                    $degrees = 180;
                    
                    break;
               
                case '4':
                    $imagick_orientation_evaluated = "Bottom-Left";
                    $degrees = 0;
                    break;
               
                case '5':
                    $imagick_orientation_evaluated = "Left-Top";
                    $degrees = 0;
                    break;
               
                case '6':
                    $imagick_orientation_evaluated = "Right-Top";
                    $degrees = 270;
                    break;
               
                case '7':
                    $imagick_orientation_evaluated = "Right-Bottom";
                    $degrees = 0;
                    break;
               
                case '8':
                    $imagick_orientation_evaluated = "Left-Bottom";
                    $degrees = 90;
                  
                    break;
            }
           

                if(isset($degrees))
                {
                $source = imagecreatefromjpeg($file_to_grab);


                $rotate = imagerotate($source, $degrees, 0);


                imagejpeg($rotate, $filename, 100);

                }
                
}
catch ( ImagickException $e )
{
   //  do something with it
}
                
                
                                  
            //    echo "<br>".homeinfo.'/testcache/1.jpg';
         }
            

           
            function getallbannerlanding()
           {
           
           $arraydata=array();
           $k=0;

           
           if(count($this->info['configall']['feature']))
           {
           foreach($this->info['configall']['feature'] as $valuefeature)
           {
            if($valuefeature['bannerlanding'])
            {
            foreach($valuefeature['bannerlanding']['web'] as $valuebannercell)
           {
           $arraydata[$k]=$valuebannercell;
           $arraydata[$k]['fid']=$valuefeature['fid'];
           $arraydata[$k]['img']=bannerinfo.'/'.$valuebannercell['img'];
           $arraydata[$k]['link']=$valuebannercell['link'];
         
           
           
           $k++;
           
           }
            }
            }
           
           
           }
           
           return $arraydata;
           
           
           }
           
           function getbannerlandingbyfid($fid)
           {
           if($fid)
           {
            $featureall=$this->getfeaturebyfid($fid,0);
            $arraydata=array();
            if(count($featureall['bannerlanding']['web']))
            {
            $k=0;
            foreach($featureall['bannerlanding']['web'] as $valuewebbanner)
            {
            
            $arraydata[$k]['img']=bannerinfo.'/'.$valuewebbanner['img'];
            $arraydata[$k]['link']=$valuewebbanner['link'];
            $arraydata[$k]['bannerid']=$valuewebbanner['bannerid'];
            $k++;
            
            }
            }
            else
            {
            $arraydata=array();
            }
            
            return $arraydata;
            
           
           }
           
           }
            
            function loadtemplate($file,$data=array(),$datasetfolder='')
            {
            
            //header('Content-Type: text/html; charset=utf-8');
            
            if(defined('privatedomain')&&privatedomain==1)
            {
            if(count($this->userdata)==0)
            {
            $url=baseinfo.'/login';
            redirectto($url);
            }
            
            
            
            }
            
            
            $data['file']=$file;
            list($urinow,$urinow2)=explode("?",$_SERVER['REQUEST_URI']);
            $data['urlnowset']=trim($urinow);
            $data['user']=$this->userdata;
            $data['feature']=$this->info['configall']['feature'];


            
            $data['bannerweb']=$this->info['configall']['banner']['web'];
            $data['nowfeature']=$this->info['config'];
            
            if(!$data['nowfeature'])
            {
            $data['tagsystem']=$this->gettagbyfid(0,1,1);
            $data['tagpoppular']=$this->gettagpoppular();
            }else
            {
            $data['tagsystem']=$this->gettagbyfid($data['nowfeature']['fid'],1,1);
            $data['tagpoppular']=$this->gettagpoppular($data['nowfeature']['fid']);
            
            }
             $time=time()+3600000;
            

            $bannerarr=$this->getallbannerlanding();
            $arrnewbanner=array();
            if(count($bannerarr))
            {
            foreach($bannerarr as $valuebannerlanding)
            {
            $arrnewbanner[$valuebannerlanding['fid']][]=$valuebannerlanding;
            
            }
            }
            $data['bannerlanding']=json_encode($arrnewbanner);
            

            $data['version']=$this->info['configall']['version'];
            $data['googleanalytic']=$this->info['configall']['googleanalytic'];
           
            if(count($this->userdata)==0)
            {

                   FacebookSession::setDefaultApplication(facebookappid,facebooksecret);

                      
                       $helper = new FacebookRedirectLoginHelper(baseinfo.'/ajax/getloginfacebook?noredirect=1&nojson=1');
                       
            
                      try {
  $session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
  // When Facebook returns an error
} catch( Exception $ex ) {
  // When validation fails or other local issues
}

// Login or logout url will be needed depending on current user state.
               
                    
                    
                         if ( isset( $session ) ) {
                      
                        $loginUrl = $helper->getLogoutUrl(); 
                        $data['linklogin']=baseinfo.'/ajax/getloginfacebook?noredirect=1&nojson=1';  
                      }else
                      { 
                      
                           
                        $params=array(
            'scope' => 'email,user_likes,user_photos,publish_stream,user_about_me,user_videos,status_update,user_birthday,user_location,user_work_history');
                       $loginUrl = $helper->getLoginUrl($params);   
                       
                       $data['linklogin']=$loginUrl;  
                      }   
                    


            
            
            }
            else
            {
             if($this->userdata['userid'])
             {
             $domain='';
             if(NameDmconnex=="Canonlife")
             {
                      $url='http://'.$_SERVER['HTTP_HOST'];
                      $domain='.'.get_domain($url);
             }
             setcookie("checkfacebookconnect",$time, $time, "/",$domain);
             }
            }
            
            if($data['user']['userid'])
            {
            $data['user']['credit']=$this->getcreditdata($data['user']['userid']);
            
            }
            
            

            
            include(templatepath.$datasetfolder.'/main.php');
            
            }
            
            function savesupermsg($msg,$productid,$orderid=0,$typeorder=0)
            {
            $arrayset['msg']=$msg;
            $arrayset['productid']=$productid;
            $arrayset['orderid']=$orderid;
            $arrayset['typeorder']=$typeorder;
            $arrayset['createby']=$_COOKIE['userid'];
            $arrayset['createdate']=date("Y-m-d H:i:s");
            
            $this->db->db_set($arrayset,'tb_super_msg');
            
            return $this->db->db_get_last_number();
            
            
            }
            
            function getreport($report,$fid=0,$status=0,$page=1,$limitdata=1)
                        {
            $page=(($page-1)*100);
            if($limitdata)
            {
            $limitset=" limit $page,100";
            }else
            {
            $limitset="";
            
            }
            
               if($report)
          {
          
             $arraydata=array();
          
              switch ($report) {
               //The Most Poppular Tag
                case 1:
                    
                    if($fid=="0"||!$fid)
                    {
                   $sql="select tb_tag.`name`,count(tb_relate_tag.tagid) as counttag 
from tb_relate_tag
inner join tb_tag on tb_tag.tagid=tb_relate_tag.tagid
INNER JOIN tb_product ON tb_product.productid =tb_relate_tag.productid
where  tb_product.delete=0
GROUP BY tb_relate_tag.tagid
order by counttag desc 
".$limitset;

$sqlcount="SELECT count(*) as countdata FROM ( select tb_tag.`name`,count(tb_relate_tag.tagid) as counttag 
from tb_relate_tag
inner join tb_tag on tb_tag.tagid=tb_relate_tag.tagid
INNER JOIN tb_product ON tb_product.productid =tb_relate_tag.productid
where  tb_product.delete=0
GROUP BY tb_relate_tag.tagid
order by counttag desc  ) tb_product ";
                    $arraydata['column'][0]['name']="name";
                    $arraydata['column'][0]['columnname']="Everything";
                    
                    
                    //$arraydata['column'][]="counttag";
//                    $arraydata['columnname'][]="Amount";
                    
                    $arraydata['column'][1]['name']="counttag";
                    $arraydata['column'][1]['columnname']="Amount";
                    
                    }else
                    {
                    
                    
                    $sql='select tb_tag.`name`,count(tb_relate_tag.tagid) as counttag
from tb_relate_tag
INNER JOIN tb_product ON tb_product.productid =tb_relate_tag.productid
inner join tb_tag on tb_tag.tagid=tb_relate_tag.tagid
where tb_product.fid='.$fid.' and tb_product.delete=0
GROUP BY tb_relate_tag.tagid
ORDER BY counttag desc '.$limitset;


                    $sqlcount='SELECT count(*) as countdata FROM (select tb_tag.`name`,count(tb_relate_tag.tagid) as counttag
from tb_relate_tag
INNER JOIN tb_product ON tb_product.productid =tb_relate_tag.productid
inner join tb_tag on tb_tag.tagid=tb_relate_tag.tagid
where tb_product.fid='.$fid.' and tb_product.delete=0
GROUP BY tb_relate_tag.tagid
ORDER BY counttag desc ) tb_product ';



                    $arraydata['column'][0]['name']="name";
                    $arraydata['column'][0]['columnname']=$this->getfeaturenamebyfid($fid);
                    

                    
                    $arraydata['column'][1]['name']="counttag";
                    $arraydata['column'][1]['columnname']="Amount";  
                    
                    //$arraydata['column'][]="name";
//                    $arraydata['columnname'][]=$this->getfeaturenamebyfid($this->post['fid']);
//                    
//                    
//                    $arraydata['column'][]="counttag";
//                    $arraydata['columnname'][]="Amount";
                    
                    
                    }
                    
                    
                    $arraydata['value']=$this->db->db_set_recordset($sql);
                   

                    break;
                    //The total of amount
                case 2:
                
                    $arraysql=array();
                    $arraysql[]='SELECT "Everything" as colname,SUM(counttag) as sumcounttag
from 
(
select tb_tag.`name`,count(tb_relate_tag.tagid) as counttag 
from tb_relate_tag
inner join tb_tag on tb_tag.tagid=tb_relate_tag.tagid
GROUP BY tb_relate_tag.tagid
order by counttag desc
) tb_tagall ';
                    if(count($this->info['configall']['feature']))
                    {
                   foreach($this->info['configall']['feature'] as $valuefeature)
                     {
                       if($valuefeature['fid']!="0"&&$valuefeature['fid']!=0)
                       {
                       $arraysql[]='SELECT "'.$valuefeature['name'].'" as colname,SUM(counttag) as sumcounttag
                                            from 
                                            (
                                            select tb_tag.`name`,count(tb_relate_tag.tagid) as counttag
                                            from tb_relate_tag
                                            INNER JOIN tb_product ON tb_product.productid =tb_relate_tag.productid
                                            inner join tb_tag on tb_tag.tagid=tb_relate_tag.tagid
                                            where tb_product.fid='.$valuefeature['fid'].'
                                            GROUP BY tb_relate_tag.tagid
                                            ORDER BY counttag desc
                                            ) tb_tagall';
                       
                       }
                     
                     }
                    }
                    

                    
                    
                    
                    $arraydata['column'][0]['name']="colname";
                    $arraydata['column'][0]['columnname']='Criteria';
                    

                    
                    $arraydata['column'][1]['name']="sumcounttag";
                    $arraydata['column'][1]['columnname']="Total";  
                    
                    
                    $sql=join(" UNION ",$arraysql).$limitset;;
                    
                    $sqlcount='select count(*) as countdata from ('.join(" UNION ",$arraysql).') tb_product';
                    
                    $arraydata['value']=$this->db->db_set_recordset($sql);
                    
                    break;
                    //The most popular product
                case 3:
                  
                  
                  $sql="SHOW TABLES LIKE 'tb_img_setting'";
         $arraycheck=$this->db->db_set_1recordrow($sql);
         
         if(count($arraycheck)==0)
                 {
                  
                     if($fid=="0"||!$fid)
                    {
                   $sql='select tb_product.title,count(tb_product.productid) as countproduct 
                   from tb_fav 
inner join tb_product on tb_product.productid=tb_fav.productid
where tb_fav.`status`=2
GROUP BY tb_product.productid
order by  countproduct desc '.$limitset;
                    $arraydata['column'][0]['name']="title";
                    $arraydata['column'][0]['columnname']="Everything";
                    
                    $arraydata['column'][1]['name']="countproduct";
                    $arraydata['column'][1]['columnname']="Amount";
                    
                    $sqlcount='SELECT count(*) as countdata from (select tb_product.title,count(tb_product.productid) as countproduct 
                   from tb_fav 
inner join tb_product on tb_product.productid=tb_fav.productid
where tb_fav.`status`=2
GROUP BY tb_product.productid
order by  countproduct desc) tb_product';
                    
                    }else
                    {
                    
                    
                    $sql='select tb_product.title,count(tb_product.productid) as countproduct from tb_fav 
inner join tb_product on tb_product.productid=tb_fav.productid
where tb_product.fid='.$fid.' and tb_fav.`status`=2
GROUP BY tb_product.productid
order by  countproduct desc '.$limitset;

                    $sqlcount='SELECT count(*) as countdata from (select tb_product.title,count(tb_product.productid) as countproduct from tb_fav 
inner join tb_product on tb_product.productid=tb_fav.productid
where tb_product.fid='.$fid.' and tb_fav.`status`=2
GROUP BY tb_product.productid
order by  countproduct desc) tb_product';

                    $arraydata['column'][0]['name']="title";
                    $arraydata['column'][0]['columnname']=$this->getfeaturenamebyfid($fid);;
                    
                    $arraydata['column'][1]['name']="countproduct";
                    $arraydata['column'][1]['columnname']="Amount";
                    
                    
                    
                    }
                    $arraydata['value']=$this->db->db_set_recordset($sql);
                 }else
                 {
                 
                     if($status==1)
                     {
                    $arraydata['column'][0]['name']="title";
                    $arraydata['column'][0]['columnname']='Camera';
                    
                    $arraydata['column'][1]['name']="countproduct";
                    $arraydata['column'][1]['columnname']="Amount";
                    
                    $sql='select tb_img_setting.make as title,count(make) as countproduct from tb_img_setting  
where tb_img_setting.make!="" and tb_img_setting.make!="    " 
GROUP BY tb_img_setting.make
ORDER BY countproduct desc '.$limitset;
                    $sqlcount='SELECT count(*) as countdata from (select tb_img_setting.make as title,count(make) as countproduct from tb_img_setting  
where tb_img_setting.make!="" and tb_img_setting.make!="    " 
GROUP BY tb_img_setting.make
ORDER BY countproduct desc ) tb_product';
                
                    
                     }else
                     {
                     
                    $arraydata['column'][0]['name']="title";
                    $arraydata['column'][0]['columnname']='Model';
                    
                    $arraydata['column'][1]['name']="countproduct";
                    $arraydata['column'][1]['columnname']="Amount";
                    
                    $sql='select tb_img_setting.model as title,count(make) as countproduct from tb_img_setting  
where tb_img_setting.model!="" and tb_img_setting.model!="    " 
GROUP BY tb_img_setting.model
ORDER BY countproduct desc '.$limitset;
                    $sqlcount='SELECT count(*) as countdata from (select tb_img_setting.model as title,count(make) as countproduct from tb_img_setting  
where tb_img_setting.model!="" and tb_img_setting.model!="    " 
GROUP BY tb_img_setting.model
ORDER BY countproduct desc ) tb_product';
                     
                     
                     }
                     
                     $arraydata['value']=$this->db->db_set_recordset($sql);
                 
                 
                 
                 }
                    
                    
                    break;
                 //The most popular member   
                   case 4:
                   
                   if($status==2)
                   {
                   $sql="SELECT
tb_user.displayname,
count(tb_follow.userid) as countfollower
FROM
tb_follow
INNER JOIN tb_user ON tb_follow.userid = tb_user.userid
where tb_follow.`status`=2
GROUP BY tb_follow.userid
order by countfollower  desc ".$limitset;
                   $sqlcount="SELECT count(*) as countdata from (SELECT
tb_user.displayname,
count(tb_follow.userid) as countfollower
FROM
tb_follow
INNER JOIN tb_user ON tb_follow.userid = tb_user.userid
where tb_follow.`status`=2
GROUP BY tb_follow.userid
order by countfollower  desc ) tb_product";


                   $arraydata['column'][0]['name']="displayname";
                   $arraydata['column'][0]['columnname']="Follower";
                   
                   
                   $arraydata['column'][1]['name']="countfollower";
                   $arraydata['column'][1]['columnname']="Amount";
                   }else
                   {
                   
                   
                   $sql="SELECT
tb_user.displayname,
count(tb_follow.createby) as countfollowing
FROM
tb_follow
INNER JOIN tb_user ON tb_follow.createby = tb_user.userid
where tb_follow.`status`=2
GROUP BY tb_follow.createby
order by countfollowing  desc ".$limitset;
                  $sqlcount="
                  SELECT count(*) as countdata from (
                  SELECT
tb_user.displayname,
count(tb_follow.createby) as countfollowing
FROM
tb_follow
INNER JOIN tb_user ON tb_follow.createby = tb_user.userid
where tb_follow.`status`=2
GROUP BY tb_follow.createby
order by countfollowing  desc ) tb_product";


                   $arraydata['column'][0]['name']="displayname";
                   $arraydata['column'][0]['columnname']="Following";
                   
                   
                   $arraydata['column'][1]['name']="countfollowing";
                   $arraydata['column'][1]['columnname']="Amount";
                   
                   
                   
                   
                   }
                   $arraydata['value']=$this->db->db_set_recordset($sql);
                   
                   break;
                 //The most popular location
                 
                  case 5:
                  
                  $sql='SELECT
tb_province.proname,
count(tb_province.proid) as countpro
FROM
tb_user
INNER JOIN tb_province ON tb_user.proid = tb_province.proid
group by  tb_province.proid
ORDER BY countpro desc

'.$limitset;

                $sqlcount='
                SELECT count(*) as countdata from (
                SELECT
tb_province.proname,
count(tb_province.proid) as countpro
FROM
tb_user
INNER JOIN tb_province ON tb_user.proid = tb_province.proid
group by  tb_province.proid
ORDER BY countpro desc
) tb_product
';
$arraydata['column'][0]['name']="proname";
$arraydata['column'][0]['columnname']="Hometown";


$arraydata['column'][1]['name']="countpro";
$arraydata['column'][1]['columnname']="Amount";

$arraydata['value']=$this->db->db_set_recordset($sql);
                    
                  break; 
                  //The Most Popular Content
                  case 6:
                  if($fid=="0"||!$fid)
                  {
                  $sql='SELECT
tb_product.title,count(tb_product.productid) as countview,(SELECT count(tb_fav.productid) as countlike from tb_fav where tb_fav.`status`=2 and tb_fav.productid=tb_product.productid) countlike
FROM
tb_product
INNER JOIN tb_view ON tb_product.productid = tb_view.productid
GROUP BY tb_product.productid 
ORDER BY countview desc
'.$limitset;             
                $sqlcount='
                SELECT count(*) as countdata from (
                SELECT
tb_product.title,count(tb_product.productid) as countview,(SELECT count(tb_fav.productid) as countlike from tb_fav where tb_fav.`status`=2 and tb_fav.productid=tb_product.productid) countlike
FROM
tb_product
INNER JOIN tb_view ON tb_product.productid = tb_view.productid
GROUP BY tb_product.productid 
ORDER BY countview desc ) tb_product
';   

$arraydata['column'][0]['name']="title";
$arraydata['column'][0]['columnname']="Everything";


$arraydata['column'][1]['name']="countview";
$arraydata['column'][1]['columnname']="Amount (view)";


$arraydata['column'][2]['name']="countlike";
$arraydata['column'][2]['columnname']="Amount (Like)";


}else
                    {
                    $sql='SELECT
tb_product.title,count(tb_product.productid) as countview,(SELECT count(tb_fav.productid) as countlike from tb_fav where tb_fav.`status`=2 and tb_fav.productid=tb_product.productid) countlike
FROM
tb_product
INNER JOIN tb_view ON tb_product.productid = tb_view.productid
where tb_product.fid='.$fid.'
GROUP BY tb_product.productid 
ORDER BY countview desc '.$limitset;
                    $sqlcount='
                    SELECT count(*) as countdata from (
                    SELECT
tb_product.title,count(tb_product.productid) as countview,(SELECT count(tb_fav.productid) as countlike from tb_fav where tb_fav.`status`=2 and tb_fav.productid=tb_product.productid) countlike
FROM
tb_product
INNER JOIN tb_view ON tb_product.productid = tb_view.productid
where tb_product.fid='.$fid.'
GROUP BY tb_product.productid 
ORDER BY countview desc ) tb_product';




$arraydata['column'][0]['name']="title";
$arraydata['column'][0]['columnname']=$this->getfeaturenamebyfid($fid);;


$arraydata['column'][1]['name']="countview";
$arraydata['column'][1]['columnname']="Amount (view)";


$arraydata['column'][2]['name']="countlike";
$arraydata['column'][2]['columnname']="Amount (Like)";
                    
                    }
                    
                    
                  $arraydata['value']=$this->db->db_set_recordset($sql);
                  break;
                  
                   //The most popular activity      
                  case 7:
                   $feature=$this->getfeaturebyname('activity');
                   
                   $arraydata['column'][0]['name']="title";
                   $arraydata['column'][0]['columnname']='Activity Name';
                   $arraydata['column'][0]['linkto']=1;
                   
                   
                   $arraydata['column'][1]['name']="votemember";
                   $arraydata['column'][1]['columnname']="Total of Like";
                   
                   
                   $arraydata['column'][2]['name']="totalphotograph";
                   $arraydata['column'][2]['columnname']="Total of Photograph";
                   
                   
                   
                   $arraydata['column'][3]['name']="totalarticle";
                   $arraydata['column'][3]['columnname']="Total of Article";
                   
                   
                   
                   $arraydata['column'][4]['name']="countview";
                   $arraydata['column'][4]['columnname']="Total of View";
                   
                   if($feature['fid'])
                   {
                        $sql='select tb_product.title,tb_product.productid,count(tb_product.productid) as votemember ,(select count(tb_view.productid) as countview from tb_view where tb_view.productid=tb_product.productid  )   as countview
                   from tb_fav 
inner join tb_product on tb_product.productid=tb_fav.productid
where tb_fav.`status`=2 and tb_product.fid='.$feature['fid'].'
GROUP BY tb_product.productid
order by  votemember desc '.$limitset;


                        $sqlcount='SELECT count(*) as countdata from ( select tb_product.title,tb_product.productid,count(tb_product.productid) as votemember ,(select count(tb_view.productid) as countview from tb_view where tb_view.productid=tb_product.productid  )   as countview
                   from tb_fav 
inner join tb_product on tb_product.productid=tb_fav.productid
where tb_fav.`status`=2 and tb_product.fid='.$feature['fid'].'
GROUP BY tb_product.productid
 ) tb_pro ';
                      
                      $arraydata['value']=$this->db->db_set_recordset($sql);
                      
                      
                      $feature2=$this->getfeaturebyname('photo');
                      
                      $feature3=$this->getfeaturebyname('article');  
                      
                      
                      
                      if(count($arraydata['value']))
                      {
                       $k=0;
                      foreach($arraydata['value'] as $valuedata)
                      {                          
                      
                              
                              $sql='select detail from  tb_plugins_hashtag where productid='.$valuedata['productid'];
                              $arrayplugin=$this->db->db_set_1recordrow($sql);
                             
                             if($feature2['fid'])
                             {
                                     $arraydata['value'][$k]['totalphotograph']= $this->countproductbytagname($arrayplugin['detail'],$feature2['fid']);
                             } else
                             {
                             
                                      $arraydata['value'][$k]['totalphotograph']=0;
                             }
                             
                             
                             
                            if($feature3['fid'])
                             { 
                             $arraydata['value'][$k]['totalarticle']= $this->countproductbytagname($arrayplugin['detail'],$feature3['fid']);
                              } else
                             {
                             $arraydata['value'][$k]['totalarticle']=0;
                             }
                      
                           // unset($arraydata['value'][$k]['productid']);
                             $k++;
                      }
                      
                      }
                      
                      
                      
                   
                   } else
                   {
                   
                   $arraydata['value']=array();
                   
                   }
                  
                   break;
                   
                   //Activity Name : Photograph Data
                   case 8:
                   
                   $feature2=$this->getfeaturebyname('photo'); 
                   
                   $arraydata['column'][0]['name']="title";
                   $arraydata['column'][0]['columnname']='Name';
                   
                   
                   $arraydata['column'][1]['name']="countview";
                   $arraydata['column'][1]['columnname']='Total View';
                   
                   
                   $arraydata['column'][2]['name']="countshare";
                   $arraydata['column'][2]['columnname']='Total Share';
                   $arraydata['column'][2]['link']=12;
                   
                   
                   $arraydata['column'][3]['name']="countlike";
                   $arraydata['column'][3]['columnname']='Total Like';
                   $arraydata['column'][3]['link']=11;
                   
                   
                   $arraydata['column'][4]['name']="newdate";
                   $arraydata['column'][4]['columnname']='Date of Post';
                   
                   
                   $arraydata['column'][5]['name']="displayname";
                   $arraydata['column'][5]['columnname']='By';
                   
                   
                   if($feature2['fid'])
                   {
                   $sql='SELECT
tb_product.productid
,tb_product.title
,(select count(tb_view.productid) as countview from tb_view where tb_view.productid=tb_product.productid  )   as countview
,(select count(tb_share_stat.productid) as countshare from tb_share_stat where tb_share_stat.productid=tb_product.productid  )   as countshare
,(select count(tb_fav.productid) as countlike from tb_fav where tb_fav.productid=tb_product.productid and tb_fav.status=2  )   as countlike
,DATE_FORMAT(tb_product.createdate,\'%b %d,%Y\')  as newdate
,IF (tb_user.displayname = \'\', tb_user.username,tb_user.displayname) as displayname
FROM
tb_product
inner join tb_user ON tb_user.userid=tb_product.createby
where tb_product.fid='.$feature2['fid'].'   and tb_product.delete=0
order by tb_product.createdate desc

'.$limitset;
                $sqlcount='SELECT count(*) as countdata from ( SELECT
tb_product.productid
,tb_product.title
,(select count(tb_view.productid) as countview from tb_view where tb_view.productid=tb_product.productid  )   as countview
,(select count(tb_share_stat.productid) as countshare from tb_share_stat where tb_share_stat.productid=tb_product.productid  )   as countshare
,(select count(tb_fav.productid) as countlike from tb_fav where tb_fav.productid=tb_product.productid and tb_fav.status=2  )   as countlike
,DATE_FORMAT(tb_product.createdate,\'%b %d,%Y\')  as newdate
,IF (tb_user.displayname = \'\', tb_user.username,tb_user.displayname) as displayname
FROM
tb_product
inner join tb_user ON tb_user.userid=tb_product.createby
where tb_product.fid='.$feature2['fid'].'   and tb_product.delete=0 ) tb_pro';


              $arraydata['value']=$this->db->db_set_recordset($sql);
                   }else
                   {
                   
               $arraydata['value']=array();    
                   }       
                   break;
                   
                   
                   //Activity Name : Article Data
                   case 9:
                   
                   $feature2=$this->getfeaturebyname('article'); 
                   
                   $arraydata['column'][0]['name']="title";
                   $arraydata['column'][0]['columnname']='Name';
                   
                   
                   $arraydata['column'][1]['name']="countview";
                   $arraydata['column'][1]['columnname']='Total View';
                   
                   
                   $arraydata['column'][2]['name']="countshare";
                   $arraydata['column'][2]['columnname']='Total Share';
                   $arraydata['column'][2]['link']=12;
                   
                   
                   $arraydata['column'][3]['name']="countlike";
                   $arraydata['column'][3]['columnname']='Total Like';
                   $arraydata['column'][3]['link']=11;
                   
                   
                   $arraydata['column'][4]['name']="newdate";
                   $arraydata['column'][4]['columnname']='Date of Post';
                   
                   
                   $arraydata['column'][5]['name']="displayname";
                   $arraydata['column'][5]['columnname']='By';
                   
                   
                   if($feature2['fid'])
                   {
                   $sql='SELECT
tb_product.productid
,tb_product.title
,(select count(tb_view.productid) as countview from tb_view where tb_view.productid=tb_product.productid  )   as countview
,(select count(tb_share_stat.productid) as countshare from tb_share_stat where tb_share_stat.productid=tb_product.productid  )   as countshare
,(select count(tb_fav.productid) as countlike from tb_fav where tb_fav.productid=tb_product.productid and tb_fav.status=2  )   as countlike
,DATE_FORMAT(tb_product.createdate,\'%b %d,%Y\')  as newdate
,IF (tb_user.displayname = \'\', tb_user.username,tb_user.displayname) as displayname
FROM
tb_product
inner join tb_user ON tb_user.userid=tb_product.createby
where tb_product.fid='.$feature2['fid'].'   and tb_product.delete=0
order by tb_product.createdate desc

'.$limitset;

                    $sqlcount='SELECT count(*) as countdata from (SELECT
tb_product.productid
,tb_product.title
,(select count(tb_view.productid) as countview from tb_view where tb_view.productid=tb_product.productid  )   as countview
,(select count(tb_share_stat.productid) as countshare from tb_share_stat where tb_share_stat.productid=tb_product.productid  )   as countshare
,(select count(tb_fav.productid) as countlike from tb_fav where tb_fav.productid=tb_product.productid and tb_fav.status=2  )   as countlike
,DATE_FORMAT(tb_product.createdate,\'%b %d,%Y\')  as newdate
,IF (tb_user.displayname = \'\', tb_user.username,tb_user.displayname) as displayname
FROM
tb_product
inner join tb_user ON tb_user.userid=tb_product.createby
where tb_product.fid='.$feature2['fid'].'   and tb_product.delete=0) tb_pro';


              $arraydata['value']=$this->db->db_set_recordset($sql);
                   }else
                   {
                   
               $arraydata['value']=array();    
                   }       
                   break;
                   
                   //Activity Name : Candidate Data
                   case 10:
                    
                    $feature2=$this->getfeaturebyname('activity'); 
                    
                    $arraydata['column'][0]['name']="firstname";
                   $arraydata['column'][0]['columnname']='Name';
                   
                   $arraydata['column'][1]['name']="lastname";
                   $arraydata['column'][1]['columnname']='Surname';
                   
                   $arraydata['column'][2]['name']="displayname";
                   $arraydata['column'][2]['columnname']='Display Name';
                    
                   $arraydata['column'][3]['name']="email";
                   $arraydata['column'][3]['columnname']='Email'; 
                   
                   $arraydata['column'][4]['name']="phone";
                   $arraydata['column'][4]['columnname']='Telephone Number'; 
                   
                   
                   $arraydata['column'][5]['name']="gender";
                   $arraydata['column'][5]['columnname']='Gender'; 
                   
                   
                   $arraydata['column'][6]['name']="age";
                   $arraydata['column'][6]['columnname']='Age'; 
                   
                   
                   $arraydata['column'][7]['name']="address";
                   $arraydata['column'][7]['columnname']='Street Address';

                   $arraydata['column'][8]['name']="subdistrict";
                   $arraydata['column'][8]['columnname']='Sub-District';
                   
                   
                   $arraydata['column'][9]['name']="district";
                   $arraydata['column'][9]['columnname']='District';
                   
                   
                   $arraydata['column'][10]['name']="province";
                   $arraydata['column'][10]['columnname']='State/Province/Region';
                   
                   
                   $arraydata['column'][11]['name']="code";
                   $arraydata['column'][11]['columnname']='Postal Code';
                   
                   $arraydata['column'][12]['name']="countryname";
                   $arraydata['column'][12]['columnname']='Country';
                   
                   
                   $arraydata['column'][13]['name']="countryname";
                   $arraydata['column'][13]['columnname']='Country';
                    
                    
                    
                    if($feature2['fid'])
                    {
                    $sql='SELECT
tb_plugins_hashtag.detail
FROM
tb_plugins_hashtag
INNER JOIN tb_product ON tb_product.productid = tb_plugins_hashtag.productid
where tb_product.fid='.$feature2['fid'].'

'.$limitset;

                     $sqlcount='SELECT count(*) as countdata from (SELECT
tb_plugins_hashtag.detail
FROM
tb_plugins_hashtag
INNER JOIN tb_product ON tb_product.productid = tb_plugins_hashtag.productid
where tb_product.fid='.$feature2['fid'].') tb_pro';
                     
                    $arraydata2=$this->db->db_set_recordset($sql);
                    $str='';
                    if(count($arraydata2))
                    {
                    foreach($arraydata2 as $valuedata2)
                    {
                    
                    if(strpos($valuedata2['detail'],'#')===false)
                    {
                    $str.='#'.$valuedata2['detail'];
                    
                    }else
                    {
                    $str.=$valuedata2['detail'];
                    
                    }
                    
                    
                    }
                    
                    }
                    $sqlarray=array();
                    if($str)
                    {
                    $arraysearch=explode("#",$str);
            $where=array();
            if(count($arraysearch))
            {
             foreach($arraysearch as $valuesearch)
             {
             if($valuesearch)
             $where[]='tb_tag.`name` like "%'.trim($valuesearch).'%"';
             
             
             }
            
            }
                      
                      $where=join(' or ',$where); 
                      $sqlarray[]='SELECT
tb_user.*


FROM
tb_product
INNER JOIN tb_relate_tag ON tb_product.productid = tb_relate_tag.productid
INNER JOIN tb_user ON tb_product.createby = tb_user.userid
INNER JOIN tb_tag ON tb_relate_tag.tagid = tb_tag.tagid
 where '.$where.' GROUP BY userid ';
                    
                    }
                    
                    
                    
                    $sqlarray[]='SELECT  tb_user.*
FROM
tb_fav
INNER JOIN tb_user ON tb_fav.createby = tb_user.userid
INNER JOIN tb_product ON tb_fav.productid = tb_product.productid
where tb_product.`delete`=0 and tb_fav.`status`=2 and tb_product.fid='.$feature2['fid'].'
GROUP BY userid ';
                    
                    
                   $sqlarray[]='SELECT
tb_user.*

FROM
tb_plugins_comment_value
INNER JOIN tb_user ON tb_plugins_comment_value.createby = tb_user.userid
INNER JOIN tb_product ON tb_plugins_comment_value.productid = tb_product.productid
where tb_product.`delete`=0  and tb_product.fid='.$feature2['fid'].'
GROUP BY userid '; 
                    
                    
                    $strsql=join(" union ",$sqlarray);
                    
                    
                    $sqlcount='SELECT count(*) as countdata from ('."select  tb_user.userid,
tb_user.firstname,
tb_user.lastname,
tb_user.displayname,
IF (tb_user.email = '', tb_user.emailfacebook,tb_user.email) as email,
tb_user.phone,
(CASE 
                    WHEN tb_user.gender = 1 THEN 'ชาย' 
                                        WHEN tb_user.gender = 2 THEN 'หญิง' 
                    ELSE 'n/a' 
                  END) gender,
IF (tb_user.birthdate = '0000-00-00','N/A',DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),tb_user.birthdate)), '%Y')+0 ) as age,
tb_user.address,
IF(tb_user.tumid = 0,'N/A',(SELECT tb_tumbon.tumname FROM  tb_tumbon where tb_tumbon.tumid=tb_user.tumid) ) as subdistrict,
IF(tb_user.disid = 0,'N/A',(SELECT tb_district.disname FROM  tb_district where tb_district.disid=tb_user.disid) ) as district,
IF(tb_user.proid = 0,'N/A',(SELECT tb_province.proname FROM  tb_province where tb_province.proid=tb_user.proid) ) as province,
tb_user.code,
IF(tb_user.countryid = 0,'N/A',(SELECT tb_country.`name` FROM  tb_country where tb_country.countryid=tb_user.countryid) ) as countryname  from ( $strsql ) tb_user group by userid  ".') tb_pro';
                    
                    $strsql="select  tb_user.userid,
tb_user.firstname,
tb_user.lastname,
tb_user.displayname,
IF (tb_user.email = '', tb_user.emailfacebook,tb_user.email) as email,
tb_user.phone,
(CASE 
                    WHEN tb_user.gender = 1 THEN 'ชาย' 
                                        WHEN tb_user.gender = 2 THEN 'หญิง' 
                    ELSE 'n/a' 
                  END) gender,
IF (tb_user.birthdate = '0000-00-00','N/A',DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),tb_user.birthdate)), '%Y')+0 ) as age,
tb_user.address,
IF(tb_user.tumid = 0,'N/A',(SELECT tb_tumbon.tumname FROM  tb_tumbon where tb_tumbon.tumid=tb_user.tumid) ) as subdistrict,
IF(tb_user.disid = 0,'N/A',(SELECT tb_district.disname FROM  tb_district where tb_district.disid=tb_user.disid) ) as district,
IF(tb_user.proid = 0,'N/A',(SELECT tb_province.proname FROM  tb_province where tb_province.proid=tb_user.proid) ) as province,
tb_user.code,
IF(tb_user.countryid = 0,'N/A',(SELECT tb_country.`name` FROM  tb_country where tb_country.countryid=tb_user.countryid) ) as countryname  from ( $strsql ) tb_user group by userid  ".$limitset;


                    
                    $arraydata['value']=$this->db->db_set_recordset($strsql);
                    
                    
                   
                    
                    }else
                    {
                    
                    $arraydata['value']=array(); 
                    
                    }
                   break; 
                   
                   case 11:
                   
                $arraydata['column'][0]['name']="displayname";
                $arraydata['column'][0]['columnname']='Like By';
                      
                   if($_GET['productid'])
                   {
                   $sql='SELECT
tb_user.displayname
FROM
tb_fav
INNER JOIN tb_user ON tb_fav.createby = tb_user.userid
where tb_fav.productid='.$_GET['productid'].$limitset;


                     $sqlcount='SELECT count(*) as countdata from (SELECT
tb_user.displayname
FROM
tb_fav
INNER JOIN tb_user ON tb_fav.createby = tb_user.userid
where tb_fav.productid='.$_GET['productid'].') tb_pro';

               $arraydata['value']=$this->db->db_set_recordset($sql);
              
                   }
                   
                   break;
                   
                   case 12:
                   
                $arraydata['column'][0]['name']="displayname";
                $arraydata['column'][0]['columnname']='Share By';
                      
                   if($_GET['productid'])
                   {
                   $sql='SELECT
IFNULL (tb_user.displayname, \'Guest\') as displayname
FROM
tb_share_stat
LEFT JOIN tb_user ON tb_share_stat.createby = tb_user.userid
where tb_share_stat.productid='.$_GET['productid'].$limitset;
               $arraydata['value']=$this->db->db_set_recordset($sql);
               
               $sqlcount='SELECT count(*) as countdata from (SELECT
IFNULL (tb_user.displayname, \'Guest\') as displayname
FROM
tb_share_stat
LEFT JOIN tb_user ON tb_share_stat.createby = tb_user.userid
where tb_share_stat.productid='.$_GET['productid'].') tb_pro';
              
                   }
                   
                   break;
                   
                   case 13:
                   
                   $arraydata['column'][0]['name']="title";
                   $arraydata['column'][0]['columnname']="Title";
                   
                   $arraydata['column'][1]['name']="user";
                   $arraydata['column'][1]['columnname']="User";
                   
                   $arraydata['column'][2]['name']="tags";
                   $arraydata['column'][2]['columnname']="Tags";
                   
                   $arraydata['column'][3]['name']="like";
                   $arraydata['column'][3]['columnname']="Like";
                   
                   $arraydata['column'][4]['name']="view";
                   $arraydata['column'][4]['columnname']="View";
                   
                   $arraydata['column'][5]['name']="comment";
                   $arraydata['column'][5]['columnname']="Comment";
                   
                   $arraydata['column'][6]['name']="bookmark";
                   $arraydata['column'][6]['columnname']="Bookmark";
                   
                   $arraydata['column'][7]['name']="share";
                   $arraydata['column'][7]['columnname']="Share";
                   
                   $arraydata['column'][8]['name']="hashtag";
                   $arraydata['column'][8]['columnname']="Hash Tags";
                   
                   $arraydata['column'][9]['name']="reservation";
                   $arraydata['column'][9]['columnname']="Reservation";
                   
                   $arraydata['column'][10]['name']="report";
                   $arraydata['column'][10]['columnname']="Report";
                   $sql='select 
title,
IF (tb_user.displayname = \'\', tb_user.username,tb_user.displayname) as `user`,
(select GROUP_CONCAT(tb_tag.`name`) AS site_list  from tb_tag INNER JOIN tb_relate_tag ON  tb_tag.tagid = tb_relate_tag.tagid where tb_relate_tag.productid=tb_product.productid) as tags,
(select count(tb_fav.favid) countfav from tb_fav where tb_fav.productid=tb_product.productid and tb_fav.`status`=2 ) as `like`,
(select count(tb_view.viewid) countview from tb_view where tb_view.productid=tb_product.productid ) as `view`,
(select count(tb_plugins_comment_value.comvid) countcomment from tb_plugins_comment_value where tb_plugins_comment_value.productid=tb_product.productid ) as `comment`,
(select count(tb_like.lid) countbookmark from tb_like where tb_like.productid=tb_product.productid ) as `bookmark`,
(select count(tb_share_stat.shareid) countshare from tb_share_stat where tb_share_stat.productid=tb_product.productid ) as `share`,
(SELECT
GROUP_CONCAT(tb_plugins_hashtag.detail) as site_list
FROM
tb_plugins_hashtag where tb_plugins_hashtag.productid=tb_product.productid  ) as `hashtag`,
(select count(tb_plugins_reservationregister_value.resvid) countshare from tb_plugins_reservationregister_value where tb_plugins_reservationregister_value.productid=tb_product.productid and tb_plugins_reservationregister_value.`delete`=0 ) as `reservation`,
(select count(tb_report.reportid) countbookmark from tb_report where tb_report.productid=tb_product.productid ) as `report`
from tb_product 
INNER JOIN tb_user ON tb_user.userid = tb_product.createby
where `delete`=0
ORDER BY tb_product.createdate desc
'.$limitset;
                $arraydata['value']=$this->db->db_set_recordset($sql);
                $sqlcount='select count(productid) as countdata from tb_product where `delete`=0';
                   break;
                
                    
                
                
                
                }
                $arcount=$this->db->db_set_1recordrow($sqlcount);
                $arraydata['countall']=$arcount['countdata'];
          
           // $this->arraydata['data']=$arraydata;
          
                    return                $arraydata;
          }
            
            
            
            }            
            function loaddata($file,$data=array(),$datasetfolder='')
            {
            if(count($this->userdata)==0)
            {
                                         FacebookSession::setDefaultApplication(facebookappid,facebooksecret);

                      
                       $helper = new FacebookRedirectLoginHelper(baseinfo.'/ajax/getloginfacebook?noredirect=1&nojson=1');
            
            
                      try {
  $session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
  // When Facebook returns an error
} catch( Exception $ex ) {
  // When validation fails or other local issues
}

// Login or logout url will be needed depending on current user state.
               
                    
                    
                         if ( isset( $session ) ) {
                      
                        $loginUrl = $helper->getLogoutUrl(); 
                        $data['linklogin']=baseinfo.'/ajax/getloginfacebook?noredirect=1&nojson=1';  
                      }else
                      { 
                      
                           
                        $params=array(
            'scope' => 'email,user_likes,user_photos,publish_stream,user_about_me,user_videos,status_update,user_birthday,user_location,user_work_history');
                       $loginUrl = $helper->getLoginUrl($params);   
                       
                       $data['linklogin']=$loginUrl;  
                      }   
                    


            
            
            }else
            {
            
            $data['linklogin']=baseinfo.'/ajax/getloginfacebook?noredirect=1&nojson=1';
            }
            
            $data['user']=$this->userdata;
            
            
            include(templatepath.$datasetfolder.'/'.$file.'.php');
            
            }
            
            function getdatarow($table,$select="",$where=array(),$onerow=0)
            {
             $wherestr="";
             if(count($where))
             {
             
             $where2=array();
             foreach($where as $keywhere => $valuewhere)
             {
              $where2[]=$keywhere."='".$valuewhere."'";
             
             }
             
             $strjoin=join(" and ",$where2); 
             
             
             
             $wherestr="where $strjoin";
             }
             
             
             if($select)
            {
            $select=mysql_real_escape_string($select);
            }else
            {
            $select=" * ";
            }
             
             
             $sql=" select $select from $table $wherestr ";
             //echo $sql;
             
            switch ($onerow) {
            case 0:
                $arraydata=$this->db->db_set_recordset($sql); 
                break;
            case 1:
                $arraydata=$this->db->db_set_1recordrow($sql);
                break;
            case 2:
                $arraydata=$this->db->db_set_recordrow($sql);
                break;
            }
             
             
            
             
             return $arraydata;
            
            }
            
            function getdistrict($proid,$getsql='disname',$swap=2)
            {
            $where['proid']=$proid;
            $arrayrow= $this->getdatarow("tb_district","disid,".$getsql,$where,$swap);
            return $arrayrow;
            }
            
            function gettumbon($disid,$getsql='tumname',$swap=2)
            {
            $where['disid']=$disid;
            $arrayrow= $this->getdatarow("tb_tumbon","tumid,".$getsql,$where,$swap);
            return $arrayrow;
            }
            
            function createdir($userid)
            {
            
            
            
            }
            
            function checkallowuserspace($userid)
            {
               return true;
            
            }
            
            function getdefault()
            {
            $arraydata=array();
            
            return $arraydata;
            
            }
            
            function getmsglistid($userid,$oauth)
            {
            $arraydata=array();
            $userdata=$this->getuserbyoauth($oauth);
        if($userdata['userid'])
            {
            
            $arraydata[]=intval($userdata['userid']);
            $arraydata[]=intval($userid);
            
            
            sort($arraydata,SORT_NUMERIC);
            
            $strjoin='|'.join("|,|",$arraydata).'|';
            
            $sql="select msglid from tb_msg_list where userids='".$strjoin."'";
            
            $data=$this->db->db_set_1recordrow($sql);
            if($data['msglid'])
            {
            
            return $data['msglid'];
            }else
            {
            $arrayset['userids']=$strjoin;
            $this->db->db_set($arrayset,'tb_msg_list');
            return $this->db->db_get_last_number();
            
            }
            
            
            
            }else
            {
            return false;
            
            }
            
            }
            
            function saveimagebase64($imgdata,$oauth)
            {
            
             $arrayuser=$this->getuserbyoauth($oauth);  
             if($arrayuser['userid'])
             {
                    
              if(!is_dir(cacheimgpath.'/user/'.$arrayuser['userid']))
                      {
                      mkdir(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      chmod(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      }
                      
            $newfie=mktime().'-'.rand(0,100000).'.jpg';
            
              $folder=cacheimgpath.'/user/'.$arrayuser['userid'];          
                      
               $fp     =fopen($folder. '/' . $newfile,'wb');
               fwrite($fp, base64_decode($imgdata));
               fclose($fp);
               chmod($folder. '/' . $newfile, 0777);
             
             
             //$this->savefile($newfie,$newfile,$folder.'/'.$newfie,"",1);
             list($width, $height, $type, $attr) = getimagesize($folder. '/' . $newfile);
             
             return $this->saveimage($width,$height,$folder.'/'.$newfie,1,'','',$newfie,1);
             }else
             {
             return false;
             
             }
             
            
            
            }
            
            function savenotificationlist($arraydata)
            {
               $arraydata['createdate']=date("Y-m-d H:i:s");
               $this->db->db_set($arraydata,"tb_notification");
               return $this->db->db_get_last_number();
            
            }
            function saveboardcasting($msg,$oauth)
            {
            $userdata=$this->getuserbyoauth($oauth);
            if($userdata['userid'])
            {
            $arraydata=array();
            if(filter_var($msg, FILTER_VALIDATE_URL) === FALSE)
            {
            $arraydata['msg']=$msg;
            $msgto= $msg;      
                    
            }else{
            $arraydata['link']=$msg; 
            $msgto= $arraydata['link'];
            }
            $arraydata['createby']=$userdata['userid'];
            $arraydata['createdate']=date("Y-m-d H:i:s");
            $this->db->db_set($arraydata,"tb_boardcasting");
            $bid=$this->db->db_get_last_number();
            
            
            $sql="select createby from tb_follow where userid=".$userdata['userid'];
            $arrayfollow=$this->db->db_set_recordset($sql);
            
            if(count($arrayfollow))
            {
            $arrayuserid=array();
            foreach($arrayfollow as $valuefollow)
            {
            $arraydataset['bid']=$bid;
            $arraydataset['conid']=5;
            $arraydataset['createby']=$userdata['userid'];
            $arraydataset['userid']=$valuefollow['createby'];
            $arrayuserid[]=$valuefollow['createby'];
            $notiid[$valuefollow['createby']]=$this->savenotificationlist($arraydataset);
            
            }
            $msgto=$userdata['displayname'].' '.$this->getconditionmsgbyid(5).' '.$msgto;
            $this->sendtonotification($arrayuserid,$msgto,$notiid);
            }
            
            
            
            return true;
            }else
            {
            return false;
            
            }
            
            
            }
            function savenotify($msg,$oauth)
            {
            $userdata=$this->getuserbyoauth($oauth);
            if($userdata['userid']&&$userdata['roleid']==3)
            {
            $arraydata=array();
            if(filter_var($msg, FILTER_VALIDATE_URL) === FALSE)
            {
            $arraydata['msg']=$msg;
            $msgto= $msg;      
                    
            }else{
            $arraydata['link']=$msg; 
            $msgto= $arraydata['link'];
            }
            $arraydata['createby']=$userdata['userid'];
            $arraydata['createdate']=date("Y-m-d H:i:s");
            $this->db->db_set($arraydata,"tb_notify");
            $notifyid=$this->db->db_get_last_number();
            
            
            $sql="select userid   from tb_user ";
            $arrayfollow=$this->db->db_set_recordset($sql);
            
            if(count($arrayfollow))
            {
            $arrayuserid=array();
            foreach($arrayfollow as $valuefollow)
            {
              
//            $arraydataset['userid']=$valuefollow['createby'];
            $arrayuserid[]=$valuefollow['userid'];
           
            
            }
              $arraydataset['notifyid']=$notifyid;
              $arraydataset['conid']=38;
              $arraydataset['createby']=$userdata['userid'];
              $arraydataset['userid']=0;
              $notiid=$this->savenotificationlist($arraydataset);              
              $arraynoti=array();
              if(count($arrayuserid))
              {
              
              foreach($arrayuserid as $valueuserid)
              {
              $arraynoti[$valueuserid]=$notiid;
              
              }
              
              }
            
            
            $msgto=$userdata['displayname'].' '.$this->getconditionmsgbyid(38).' '.$msgto;
            $this->sendtonotification($arrayuserid,$msgto,$arraynoti);
            }
            
            
            
            return true;
            }else
            {
            return false;
            
            }
            
            
            }
            
            function getconditionmsgbyid($conid)
            {
            
            $sql="select msg from tb_condition where conid=".$conid;
            $arraycondition=$this->db->db_set_1recordrow($sql);
            return $arraycondition['msg'];
            
            }
            
            function gettagproductdata()
            {
            
            $sql='SELECT
tb_tag.*,
tb_relate_tag.productid
FROM
tb_plugins_price
INNER JOIN (select productid,fid from  tb_product where tb_product.`delete`=0 and tb_product.status=1) tb_product ON tb_product.productid = tb_plugins_price.productid
INNER JOIN tb_relate_tag  ON tb_relate_tag.productid =tb_product.productid
INNER JOIN tb_tag  ON tb_tag.tagid =tb_relate_tag.tagid
where tb_tag.system=1
group by tb_tag.tagid
order by tb_tag.createdate asc 

';

                $tagproduct=$this->db->db_set_recordset($sql);
                return $tagproduct;
            
            }
            
            
            
            function getproductpricedata()
            {
            
           
            
           $innerjoin=' INNER JOIN tb_plugins_price ON tb_product.productid = tb_plugins_price.productid ';
           $where=' where tb_product.delete=0 and  tb_product.status=1';
           
            return $this->getproductbycondition($where,'','',$innerjoin,'','',1);

              //  $tagproduct=$this->db->db_set_recordset($sql);
               // return $tagproduct;
            
            }
            
            
            function getpoppularpricedata()
            {
            
           
            
           $innerjoin=' INNER JOIN tb_product_suborder ON tb_product.productid = tb_product_suborder.productid ';
           $where=' where tb_product.delete=0 and tb_product_suborder.discount=0 and  tb_product.status=1 ';
           
            return $this->getproductbycondition($where,'limit 0,10',' order by countproduct desc',$innerjoin,' group by tb_product_suborder.productid ',',count(tb_product_suborder.productid) as countproduct',1);

              //  $tagproduct=$this->db->db_set_recordset($sql);
               // return $tagproduct;
            
            }
            
            function getcreditbyuserid($userid)
            {
            
            $sql='select  SUM(credit) as sumcredit  from tb_credit where tb_credit.userid='.$userid;
            $arraycredit=$this->db->db_set_1recordrow($sql);
            if(!$arraycredit['sumcredit'])
            {
            $arraycredit['sumcredit']=0;
            }
            return $arraycredit['sumcredit'];
            
            
            }
            
            function getorderlistbyuserid($userid)
            {
            
            $sql='SELECT count(wo.orderid)  as countorder FROM tb_product_order wo  
WHERE wo.createdate >= curdate() - INTERVAL DATE_FORMAT(NOW(),\'%w\') DAY and userid='.$userid.'

UNION

SELECT count(wo.orderid)  as countorder FROM tb_product_order wo  
WHERE wo.createdate >=  DATE_FORMAT(NOW(),\'%Y-%m-1\') and userid='.$userid.' 

UNION

SELECT count(wo.orderid)  as countorder FROM tb_product_order wo 
WHERE userid='.$userid.'


';

$sql='SELECT count(wo.orderid)  as countorderweek,(SELECT count(wo.orderid)  as countorder FROM tb_product_order wo  
WHERE wo.createdate >=  DATE_FORMAT(NOW(),\'%Y-%m-1\') and userid='.$userid.' and status=2   ) as countordermonth, (SELECT count(wo.orderid)  as countorder FROM tb_product_order wo 
WHERE userid='.$userid.' and status=2 ) as countorderall  FROM tb_product_order wo  
WHERE wo.createdate >= curdate() - INTERVAL DATE_FORMAT(NOW(),\'%w\') DAY and userid='.$userid.' and status=2 ';


$arraydata=$this->db->db_set_1recordrow($sql);


          $arraydata['orderlist']=$this->getorderlistdatabyuserid($userid,1);
             

        
          
          
          

          return $arraydata;



            
            
            
            }
            
            function saveorderdata($suborder,$status,$sumall,$cash,$change,$point,$userid,$shopid,$orderid=0)
          {
          
           $arraynewdata=array();
           if(count($suborder)&&$status)
           {
           $arrayorder=array();
           $arrayorder['status']=$status;
           $arrayorder['sumall']=$sumall;
           $arrayorder['cash']=$cash;
           $arrayorder['change']=$change;
           $arrayorder['userid']=$userid;
           $arrayorder['point']=$point;
       
           $arrayorder['updateby']=$shopid;
           $arrayorder['updatedate']=date('Y-m-d H:i:s');
           $new=0;
           if($orderid)
           {
          
           
           $this->db->db_set($arrayorder,'tb_product_order',' orderid='.$orderid);
           
           
           
           }else
           {
           $new=1;
           $arrayorder['createby']=$shopid;
           $arrayorder['createdate']=date('Y-m-d H:i:s');
           
           $this->db->db_set($arrayorder,'tb_product_order');
           $orderid=$this->db->db_get_last_number();
           
           
           }
           
           $arraynewdata['orderid']=$orderid;
           
           $sql='delete from tb_product_suborder where orderid='.$orderid;
           $this->db->db_delete($sql);
           
            if(count($suborder))
           {
           foreach($suborder as $valuesuborder)
           {
           $arraysuborder=array(); 
           $arraysuborder['productid']=$valuesuborder['productid'];
           $arraysuborder['credit']=$valuesuborder['credit'];
           $arraysuborder['count']=$valuesuborder['count'];
           $arraysuborder['point']=$valuesuborder['point'];
           if($valuesuborder['productid'])
           {
           
           }else
           {
           
           $arraysuborder['title']=$valuesuborder['title'];
           }
           
           $arraysuborder['orderid']=$orderid;
           $arraysuborder['discount']=$valuesuborder['discount'];
           $arraysuborder['price']=$valuesuborder['price'];
           $arraysuborder['note']=$valuesuborder['note'];
           
            if($valuesuborder['suborderid'])
           {
          
           
           $this->db->db_set($arraysuborder,'tb_product_suborder',' suborderid='.$valuesuborder['suborderid']);
           
           
           
           }else
           {
           
           $this->db->db_set($arraysuborder,'tb_product_suborder');
           $suborderid=$this->db->db_get_last_number();
           $arraynewdata['suborderids'][]=$suborderid;
           }
           
           
           
           
           
           }
           
           }
           
         
           
           
           }
          
          
          return $arraynewdata;
          
          }
            
            function saveproducttranfer($qty,$status,$userid,$productid,$orderid,$suborderid)
            {
            
            $arraydata['qty']=$qty;
            $arraydata['status']=$status;
            $arraydata['productid']=$productid;
            $arraydata['createby']=$userid;
            $arraydata['userid']=$this->userdata['userid'];
            $arraydata['orderid']=$orderid;
            $arraydata['suborderid']=$suborderid;
            $arraydata['createdate']=date('Y-m-d H:i:s');
            $this->db->db_set($arraydata,'tb_product_transaction');
            
            
            }
            
            function sendemailbyorderid($orderid)
            {
            
            
            $sql='SELECT * FROM `tb_product_order` where tb_product_order.orderid='.$orderid;
            $arrayproduct=$this->db->db_set_1recordrow($sql);
            
            
            $sql='select 
IF (tb_product_setting.shopname is NULL,tb_user.displayname,tb_product_setting.shopname) as displayname,
tb_user.username,
IF (tb_product_setting.orderprefix is NULL,\'\',tb_product_setting.orderprefix) as orderprefix,
IF (tb_user.email,tb_user.email,tb_user.emailfacebook) as email

 from tb_user 

 LEFT JOIN tb_product_setting ON tb_user.userid = tb_product_setting.createby

 where tb_user.userid='.$arrayproduct['createby'];
            $arraysetting=$this->db->db_set_1recordrow($sql);
            
            
            $sql='SELECT
tb_product_suborder.suborderid,
tb_product_suborder.productid,
tb_product_suborder.credit,
tb_product_suborder.point,
tb_product_suborder.count,
tb_product_suborder.`delete`,
tb_product_suborder.orderid,
tb_product_suborder.title,
tb_product_suborder.note,
tb_product_suborder.discount,
tb_product_suborder.price,
tb_product.title
FROM
tb_product_suborder
INNER JOIN tb_product ON tb_product_suborder.productid = tb_product.productid  where tb_product_suborder.orderid='.$orderid;
            $arraysuborder=$this->db->db_set_recordset($sql);
            
            
            
           $code  = '<html xmlns="http://www.w3.org/1999/xhtml"><head>'."\n";
$code .= '    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">'."\n";
$code .= '    <meta content="width=device-width, initial-scale=1.0" name="viewport">'."\n";
$code .= '    <title>Order Information</title>'."\n";
$code .= '    <style type="text/css">'."\n";
$code .= '        #outlook a {padding:0;}'."\n";
$code .= '        body{width:100% !important; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%; margin:0; padding:0;} '."\n";
$code .= '        .ExternalClass {width:100%;} '."\n";
$code .= '        .ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {line-height: 100%;}'."\n";
$code .= '        #backgroundTable {margin:0; padding:0; width:100% !important; line-height: 100% !important;}'."\n";
$code .= '        img {outline:none; text-decoration:none; -ms-interpolation-mode: bicubic;} '."\n";
$code .= '        a img {border:none;} '."\n";
$code .= '        .image_fix {display:block;}'."\n";
$code .= '        p {margin: 1em 0;}'."\n";
$code .= '        h1, h2, h3, h4, h5, h6 {color: black !important;}'."\n";
$code .= '        h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {color: blue !important;}'."\n";
$code .= '        h1 a:active, h2 a:active,  h3 a:active, h4 a:active, h5 a:active, h6 a:active {'."\n";
$code .= '        color: red !important;'."\n";
$code .= '        }'."\n";
$code .= '        h1 a:visited, h2 a:visited,  h3 a:visited, h4 a:visited, h5 a:visited, h6 a:visited {'."\n";
$code .= '        color: purple !important;'."\n";
$code .= '        }'."\n";
$code .= '        table td {border-collapse: collapse;}'."\n";
$code .= '        table { border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; }'."\n";
$code .= '        a {color: orange;}'."\n";
$code .= '        @media only screen and (max-device-width: 480px) {'."\n";
$code .= '            a[href^="tel"], a[href^="sms"] {'."\n";
$code .= '                        text-decoration: none;'."\n";
$code .= '                        color: blue;'."\n";
$code .= '                        pointer-events: none;'."\n";
$code .= '                        cursor: default;'."\n";
$code .= '                    }'."\n";
$code .= "\n";
$code .= '            .mobile_link a[href^="tel"], .mobile_link a[href^="sms"] {'."\n";
$code .= '                        text-decoration: default;'."\n";
$code .= '                        color: orange !important;'."\n";
$code .= '                        pointer-events: auto;'."\n";
$code .= '                        cursor: default;'."\n";
$code .= '                    }'."\n";
$code .= "\n";
$code .= '        }'."\n";
$code .= '        @media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {'."\n";
$code .= '            a[href^="tel"], a[href^="sms"] {'."\n";
$code .= '                        text-decoration: none;'."\n";
$code .= '                        color: blue;'."\n";
$code .= '                        pointer-events: none;'."\n";
$code .= '                        cursor: default;'."\n";
$code .= '                    }'."\n";
$code .= "\n";
$code .= '            .mobile_link a[href^="tel"], .mobile_link a[href^="sms"] {'."\n";
$code .= '                        text-decoration: default;'."\n";
$code .= '                        color: orange !important;'."\n";
$code .= '                        pointer-events: auto;'."\n";
$code .= '                        cursor: default;'."\n";
$code .= '                    }'."\n";
$code .= '        }'."\n";
$code .= '        @media only screen and (-webkit-min-device-pixel-ratio: 2) {}'."\n";
$code .= '        @media only screen and (-webkit-device-pixel-ratio:.75){}'."\n";
$code .= '        @media only screen and (-webkit-device-pixel-ratio:1){}'."\n";
$code .= '        @media only screen and (-webkit-device-pixel-ratio:1.5){}'."\n";
$code .= '    </style>'."\n";
$code .= '</head>'."\n";
$code .= '<body>'."\n";



$code .= '<table border="0" cellspacing="0" cellpadding="0" style="font-family: Arial, Helvetica, sans-serif;min-width:320px;font-size:16px;" id="backgroundTable">'."\n";
$code .= '    <tbody><tr>'."\n";
$code .= '        <td valign="top" style="padding:20px;line-height:20px;">'."\n";
$code .= '            <table border="0" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr style="height: 80px;font-size:20px;">'."\n";
$code .= '                    <td colspan="2">คุณได้ทำรายการสั่งซื้อสินค้า</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '            </tbody></table> '."\n";
$code .= '            <table border="0" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr>'."\n";
$code .= '                    <td style="font-weight:bold;">Shop :</td>'."\n";



$code .= '                    <td><a href="'.baseinfo.'/'.$arraysetting['username'].'">'.$arraysetting['displayname'].'</a></td>'."\n";


$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;">Order ID :</td>'."\n";
$code .= '                    <td><a href="">'.$arraysetting['orderprefix'].''.$arrayproduct['orderid'].'</a></td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";

$code .= '                    <td style="font-weight:bold;">Order On :</td>'."\n";
$code .= '                    <td>'.date('d/m/d H:i:s',strtotime($arrayproduct['createdate'])) .'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;">Status :</td>'."\n";
$code .= '                    <td>Reserve</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '            </tbody></table>'."\n";
$code .= '            <table border="1" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr style="font-weight:bold;background-color:#666;color:#fff;">'."\n";
$code .= '                    <td style="padding: 5px;">Product</td>'."\n";
$code .= '                    <td style="padding: 5px 10px;">Price (Baht)</td>'."\n";
$code .= '                    <td style="padding: 5px 10px;">Qty</td>'."\n";
$code .= '                    <td style="padding: 5px 10px;">Amount (Baht)</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                '."\n";

if(count($arraysuborder))
{
foreach($arraysuborder as $valusuborder)
{

if($valusuborder['discount']=='0')
{
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;">'."\n";
$code .= '                        <span style="font-weight:bold;display:block;"><a href="'.baseinfo.'/post/'.$valusuborder['productid'].'">'.$valusuborder['title'].'</a></span>'."\n";
//$code .= '                        <span>Main Attribute : Sub Attribute</span>'."\n";
$code .= '                    </td>'."\n";
$code .= '                    <td style="padding: 5px 10px;text-align:center;">'.$valusuborder['price'].'</td>'."\n";
$code .= '                    <td style="padding: 5px 10px;text-align:center;">'.$valusuborder['count'].'</td>'."\n";
$code .= '                    <td style="padding: 5px 10px;text-align:center;">'.(intval($valusuborder['count'])*intval($valusuborder['count'])).'</td>'."\n";
$code .= '                </tr>'."\n";
}

}
}

if(count($arraysuborder))
{
foreach($arraysuborder as $valusuborder)
{

if($valusuborder['price']=='0')
{
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;" colspan="3">'."\n";
$code .= '                        <span>'.$valusuborder['title'].'</span>'."\n";
$code .= '                    </td>'."\n";
$code .= '                    <td style="padding: 5px;text-align:center;">-'.$valusuborder['discount'].'</td>'."\n";
$code .= '                </tr>'."\n";
}
}
}




if($arrayproduct['tspoid'])
{
$sql='select * from tb_product_transport where tb_product_transport.tspoid='.$arrayproduct['tspoid'];
$arraytransport=$this->db->db_set_1recordrow($sql);

if($arraytransport['tspoid'])
{
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;" colspan="3">'."\n";
$code .= '                        <span style="font-weight:bold;">วิธีรับสินค้า : </span>'."\n";
$code .= '                        <span>'.$arraytransport['tspoid'].'</span>'."\n";
$code .= '                    </td>'."\n";
$code .= '                    <td style="padding: 5px;text-align:center;">'.$arraytransport['tspcost'].'</td>'."\n";
$code .= '                </tr>'."\n";
}

}

$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;font-size:20px;" colspan="3">'."\n";
$code .= '                        <span style="font-weight:bold;text-align:right;display:block;">Total</span>'."\n";
$code .= '                    </td>'."\n";
$code .= '                    <td style="padding: 5px;text-align:center;font-weight:bold;font-size:20px;">'.$arrayproduct['sumall'].'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '            </tbody></table>'."\n";
$code .= '            <table border="1" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr>'."\n";
$code .= '                    <td style="font-weight:bold;background-color:#666;color:#fff;padding: 5px;" colspan="4">Shipping Information</td>'."\n";
$code .= '                </tr>'."\n";

$sql='SELECT
tb_user.userid,
tb_user.shop,
tb_user.uuid,
tb_user.facebookid,
tb_user.oauth,
tb_user.badge,
tb_user.roleid,
tb_user.coimgid,
tb_user.imgmid,
tb_user.simgmid,
tb_user.bannerimgmid,
tb_user.sbannerimgmid,
tb_user.langid,
tb_user.statusalert,
tb_user.statussound,
tb_user.statusvibration,
tb_user.publish,
tb_user.post,
tb_user.emailcontact,
tb_user.myfacebook,
tb_user.autofacebook,
tb_user.mytwitter,
tb_user.autotwitter,
tb_user.mygoogleplus,
tb_user.autogoogleplus,
tb_user.`status`,
tb_user.username,
tb_user.firstname,
tb_user.lastname,
tb_user.description,
tb_user.displayname,
tb_user.`password`,
tb_user.email,
tb_user.emailfacebook,
tb_user.gender,
tb_user.lat,
tb_user.lng,
tb_user.birthdate,
tb_user.address,
tb_user.countryid,
tb_user.proid,
tb_user.disid,
tb_user.space,
tb_user.tumid,
tb_user.forgetcode,
tb_user.`code`,
tb_user.state,
tb_user.sameaddress,
tb_user.shipaddress,
tb_user.shipcountryid,
tb_user.shipproid,
tb_user.shipdisid,
tb_user.shiptumid,
tb_user.shipstate,
tb_user.shipcode,
tb_user.facebook,
tb_user.twitter,
tb_user.googleplus,
tb_user.website,
tb_user.phone,
tb_user.fax,
tb_user.createdate,
tb_user.etc,
tb_user.syncfacebook,
tb_user.syncuser,
tb_user.readsync,
tb_district.disname,
tb_tumbon.tumname,
tb_province.proname
FROM
tb_user
LEFT JOIN tb_district ON tb_user.shipdisid = tb_district.disid
LEFT JOIN tb_tumbon ON tb_user.shiptumid = tb_tumbon.tumid
LEFT JOIN tb_province ON tb_user.shipproid = tb_province.proid where tb_user.userid='.$arrayproduct['userid'];
$arraycustomer=$this->db->db_set_1recordrow($sql);

$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;padding: 5px;">Name :</td>'."\n";
$code .= '                    <td style="padding: 5px;">'.$arraycustomer['displayname'].'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;padding: 5px;">Email :</td>'."\n";
$code .= '                    <td style="padding: 5px;">'.$arraycustomer['emailcontact'].'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;padding: 5px;">Tel :</td>'."\n";
$code .= '                    <td style="padding: 5px;">'.$arraycustomer['phone'].'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;padding: 5px;">Address :</td>'."\n";
$strtext='';
if($arraycustomer['shipcountryid']=='210')
{



$strtext=$arraycustomer['disname'].' '.$arraycustomer['tumname'].' '.$arraycustomer['proname'].' '.$arraycustomer['shipcode'];

}else
{

$strtext=$arraycustomer['shipstate'].' '.$arraycustomer['shipcode'];

}

$code .= '                    <td style="padding: 5px;">'.$arraycustomer['address'].' '.$strtext.'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '            </tbody></table>'."\n";
$code .= '            <table border="0" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr>'."\n";
$code .= '                    <td style="font-weight:bold;background-color:#666;color:#fff;padding: 5px;" colspan="4">More Information</td>'."\n";
$code .= '                </tr>'."\n";

//$code .= '                <tr>'."\n";
//$code .= '                    <td style="padding: 5px;">Bla Bla Bla</td>'."\n";
//$code .= '                </tr>'."\n";

$code .= '            </tbody></table>'."\n";
$code .= '            <table border="0" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr>'."\n";
$code .= '                    <td style="font-weight:bold;background-color:#666;color:#fff;padding: 5px;" colspan="4">How to Pay</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;">No payment channel, contact the shop about the details of payment.</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;">'."\n";
$code .= '                        <div style="font-weight:bold;">1. Transfer</div>'."\n";
$code .= '                    </td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;">'."\n";
$code .= '                        <table border="1" cellspacing="0" cellpadding="0" style="margin-left:20px;">'."\n";
$code .= '                            <tbody><tr style="font-weight:bold;background-color:#999;color:#fff;text-align:center;">'."\n";
$code .= '                                <td style="padding: 5px">Bank</td>'."\n";
$code .= '                                <td style="padding: 5px">Branch</td>'."\n";
$code .= '                                <td style="padding: 5px">Number</td>'."\n";
$code .= '                                <td style="padding: 5px">Type</td>'."\n";
$code .= '                                <td style="padding: 5px">Name</td>'."\n";
$code .= '                            </tr>'."\n";


$sql='SELECT
tb_product_transfer_bank.bankname,
tb_product_transfer_type.typename,
tb_product_transfer.branch,
tb_product_transfer.accname,
tb_product_transfer.accnumber,
tb_product_transfer.tfid
FROM
tb_product_transfer
INNER JOIN tb_product_transfer_bank ON tb_product_transfer.bankid = tb_product_transfer_bank.bankid
INNER JOIN tb_product_transfer_type ON tb_product_transfer.actypeid = tb_product_transfer_type.actypeid
where tb_product_transfer.createby='.$arrayproduct['createby'].'
';

$arraytranferdata=$this->db->db_set_recordset($sql);


if(count($arraytranferdata))
{
foreach($arraytranferdata as $valuetranfer)
{
$code .= '                            <tr>'."\n";
$code .= '                                <td style="padding: 5px 10px;text-align:center;">'.$valuetranfer['bankname'].'</td>'."\n";
$code .= '                                <td style="padding: 5px 10px;text-align:center;">'.$valuetranfer['branch'].'</td>'."\n";
$code .= '                                <td style="padding: 5px 10px;text-align:center;">'.$valuetranfer['accnumber'].'</td>'."\n";
$code .= '                                <td style="padding: 5px 10px;text-align:center;">'.$valuetranfer['typename'].'</td>'."\n";
$code .= '                                <td style="padding: 5px 10px;text-align:center;">'.$valuetranfer['accname'].'</td>'."\n";
$code .= '                            </tr>'."\n";
}
}


$code .= '                        </tbody></table>'."\n";
$code .= '                    </td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                    <tr><td style="padding: 5px;"><a style="margin-left:20px;" href="">แจ้งชำระเงิน</a></td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '            </tbody></table>'."\n";
$code .= '        </td>'."\n";
$code .= '    </tr>'."\n";
$code .= '</tbody></table>  '."\n";
$code .= "\n";
$code .= "\n";
$code .= '</body></html>';


            require_once(pluginpath.'/phpmailer/class.config.php'); // uri
           
           $mail = new ConfigMail();
           //$mail->setFrom("s_chanyut@hotmail.com","Bird Kung");
           $mail->setTo($arraycustomer['emailcontact'],$arraycustomer['displayname']);
           $mail->setContent($code);
           $mail->setSubject("คุณได้ทำรายการสั่งซื้อสินค้า");
           $mail->sendTo();
           
           
           
           $code=str_replace('คุณได้ทำรายการสั่งซื้อสินค้า',',มีลูกค้าทำรายการการสั่งซื้อ',$code);
           
           $mail->setClearAddress();
           $mail->setTo($arraysetting['email'],$arraysetting['displayname']);
           $mail->setContent($code);
           $mail->setSubject("มีคนทำรายการสั่งซื้อสินค้า");
           $mail->sendTo();
           
           
           
            
            
            }
            
            
            
            function sendemailpaybyorderid($orderid)
            {
            
            
            $sql='SELECT * FROM `tb_product_order` where tb_product_order.orderid='.$orderid;
            $arrayproduct=$this->db->db_set_1recordrow($sql);
            
            
            $sql='select 
IF (tb_product_setting.shopname is NULL,tb_user.displayname,tb_product_setting.shopname) as displayname,
tb_user.username,
IF (tb_product_setting.orderprefix is NULL,\'\',tb_product_setting.orderprefix) as orderprefix,
IF (tb_user.email,tb_user.email,tb_user.emailfacebook) as email

 from tb_user 

 LEFT JOIN tb_product_setting ON tb_user.userid = tb_product_setting.createby

 where tb_user.userid='.$arrayproduct['createby'];
            $arraysetting=$this->db->db_set_1recordrow($sql);
            
            
            $sql='SELECT
tb_product_suborder.suborderid,
tb_product_suborder.productid,
tb_product_suborder.credit,
tb_product_suborder.point,
tb_product_suborder.count,
tb_product_suborder.`delete`,
tb_product_suborder.orderid,
tb_product_suborder.title,
tb_product_suborder.note,
tb_product_suborder.discount,
tb_product_suborder.price,
tb_product.title
FROM
tb_product_suborder
INNER JOIN tb_product ON tb_product_suborder.productid = tb_product.productid  where tb_product_suborder.orderid='.$orderid;
            $arraysuborder=$this->db->db_set_recordset($sql);
            
            
            
           $code  = '<html xmlns="http://www.w3.org/1999/xhtml"><head>'."\n";
$code .= '    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">'."\n";
$code .= '    <meta content="width=device-width, initial-scale=1.0" name="viewport">'."\n";
$code .= '    <title>Order Information</title>'."\n";
$code .= '    <style type="text/css">'."\n";
$code .= '        #outlook a {padding:0;}'."\n";
$code .= '        body{width:100% !important; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%; margin:0; padding:0;} '."\n";
$code .= '        .ExternalClass {width:100%;} '."\n";
$code .= '        .ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {line-height: 100%;}'."\n";
$code .= '        #backgroundTable {margin:0; padding:0; width:100% !important; line-height: 100% !important;}'."\n";
$code .= '        img {outline:none; text-decoration:none; -ms-interpolation-mode: bicubic;} '."\n";
$code .= '        a img {border:none;} '."\n";
$code .= '        .image_fix {display:block;}'."\n";
$code .= '        p {margin: 1em 0;}'."\n";
$code .= '        h1, h2, h3, h4, h5, h6 {color: black !important;}'."\n";
$code .= '        h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {color: blue !important;}'."\n";
$code .= '        h1 a:active, h2 a:active,  h3 a:active, h4 a:active, h5 a:active, h6 a:active {'."\n";
$code .= '        color: red !important;'."\n";
$code .= '        }'."\n";
$code .= '        h1 a:visited, h2 a:visited,  h3 a:visited, h4 a:visited, h5 a:visited, h6 a:visited {'."\n";
$code .= '        color: purple !important;'."\n";
$code .= '        }'."\n";
$code .= '        table td {border-collapse: collapse;}'."\n";
$code .= '        table { border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; }'."\n";
$code .= '        a {color: orange;}'."\n";
$code .= '        @media only screen and (max-device-width: 480px) {'."\n";
$code .= '            a[href^="tel"], a[href^="sms"] {'."\n";
$code .= '                        text-decoration: none;'."\n";
$code .= '                        color: blue;'."\n";
$code .= '                        pointer-events: none;'."\n";
$code .= '                        cursor: default;'."\n";
$code .= '                    }'."\n";
$code .= "\n";
$code .= '            .mobile_link a[href^="tel"], .mobile_link a[href^="sms"] {'."\n";
$code .= '                        text-decoration: default;'."\n";
$code .= '                        color: orange !important;'."\n";
$code .= '                        pointer-events: auto;'."\n";
$code .= '                        cursor: default;'."\n";
$code .= '                    }'."\n";
$code .= "\n";
$code .= '        }'."\n";
$code .= '        @media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {'."\n";
$code .= '            a[href^="tel"], a[href^="sms"] {'."\n";
$code .= '                        text-decoration: none;'."\n";
$code .= '                        color: blue;'."\n";
$code .= '                        pointer-events: none;'."\n";
$code .= '                        cursor: default;'."\n";
$code .= '                    }'."\n";
$code .= "\n";
$code .= '            .mobile_link a[href^="tel"], .mobile_link a[href^="sms"] {'."\n";
$code .= '                        text-decoration: default;'."\n";
$code .= '                        color: orange !important;'."\n";
$code .= '                        pointer-events: auto;'."\n";
$code .= '                        cursor: default;'."\n";
$code .= '                    }'."\n";
$code .= '        }'."\n";
$code .= '        @media only screen and (-webkit-min-device-pixel-ratio: 2) {}'."\n";
$code .= '        @media only screen and (-webkit-device-pixel-ratio:.75){}'."\n";
$code .= '        @media only screen and (-webkit-device-pixel-ratio:1){}'."\n";
$code .= '        @media only screen and (-webkit-device-pixel-ratio:1.5){}'."\n";
$code .= '    </style>'."\n";
$code .= '</head>'."\n";
$code .= '<body>'."\n";






$code .= '<table border="0" cellspacing="0" cellpadding="0" style="font-family: Arial, Helvetica, sans-serif;min-width:320px;font-size:16px;" id="backgroundTable">'."\n";
$code .= '    <tbody><tr>'."\n";
$code .= '        <td valign="top" style="padding:20px;line-height:20px;">'."\n";

  $sql='SELECT
tb_product_transfer_bank.bankname,
tb_product_transfer.accnumber,
tb_product_transfer.accname,
tb_product_transfer.branch,
tb_product_transfer_type.typename,
tb_product_userpay.upayid,
tb_product_userpay.tfid,
tb_product_userpay.orderid,
tb_product_userpay.shopid,
DATE_FORMAT(tb_product_userpay.createdate,\'%T %d/%m/%Y\') as newcreatedate,
DATE_FORMAT(tb_product_userpay.datepay,\'%d/%m/%Y\') as newdatepay,
DATE_FORMAT(tb_product_userpay.datepay,\'%T\') as newtimedatepay,
tb_product_userpay.datepay,
tb_product_userpay.amount,
tb_product_userpay.detail,
tb_product_userpay.imgmid,
tb_product_userpay.simgmid,
tb_product_userpay.createby,
tb_product_userpay.createdate
FROM
tb_product_userpay
INNER JOIN tb_product_transfer ON tb_product_userpay.tfid = tb_product_transfer.tfid
INNER JOIN tb_product_transfer_bank ON tb_product_transfer.bankid = tb_product_transfer_bank.bankid
INNER JOIN tb_product_transfer_type ON tb_product_transfer.actypeid = tb_product_transfer_type.actypeid
where tb_product_userpay.orderid='.$orderid;
$arrayuserpay=$this->db->db_set_recordset($sql);


$code .= '<table border="0" cellspacing="0" cellpadding="0" style="margin-bottom:20px">'."\n";
$code .= '<tbody><tr style="height:80px;font-size:20px">'."\n";
$code .= '<td colspan="2">ทางร้านได้รับยอดเงินเรียบร้อยแล้ว&rlm;</td>'."\n";
$code .= '</tr>'."\n";

if(count($arrayuserpay))
{
foreach($arrayuserpay as $valueuserpay)
{
$code .= '<tr>'."\n";
$code .= '<td style="font-weight:bold">Inform Date :</td>'."\n";
$code .= '<td>'.$valueuserpay['newcreatedate'].'</td>'."\n";
$code .= '</tr>'."\n";
$code .= '<tr>'."\n";
$code .= '<td style="font-weight:bold">Method :</td>'."\n";
$code .= '<td>Transfer : '.$valueuserpay['bankname'].' '.$valueuserpay['branch'].' '.$valueuserpay['accnumber'].'</td>'."\n";
$code .= '</tr>'."\n";
$code .= '<tr>'."\n";
$code .= '<td style="font-weight:bold">Payment Date :</td>'."\n";
$code .= '<td>'.$valueuserpay['newdatepay'].'</td>'."\n";
$code .= '</tr>'."\n";
$code .= '<tr>'."\n";
$code .= '<td style="font-weight:bold">Payment Time :</td>'."\n";
$code .= '<td>'.$valueuserpay['newtimedatepay'].'</td>'."\n";
$code .= '</tr>'."\n";
$code .= '<tr>'."\n";
$code .= '<td style="font-weight:bold">Amount :</td>'."\n";
$code .= '<td>'.$valueuserpay['amount'].' Baht</td>'."\n";
$code .= '</tr>'."\n";
$code .= '<tr>'."\n";
$code .= '<td style="font-weight:bold">More Details :</td>'."\n";
$code .= '<td>'.$valueuserpay['detail'].'</td>'."\n";
$code .= '</tr>'."\n";
}
}

$code .= '</tbody></table>';



$code .= '            <table border="0" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr>'."\n";
$code .= '                    <td style="font-weight:bold;">Shop :</td>'."\n";



$code .= '                    <td><a href="'.baseinfo.'/'.$arraysetting['username'].'">'.$arraysetting['displayname'].'</a></td>'."\n";


$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;">Order ID :</td>'."\n";
$code .= '                    <td><a href="">'.$arraysetting['orderprefix'].''.$arrayproduct['orderid'].'</a></td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";

$code .= '                    <td style="font-weight:bold;">Order On :</td>'."\n";
$code .= '                    <td>'.date('d/m/d H:i:s',strtotime($arrayproduct['createdate'])) .'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;">Status :</td>'."\n";
$code .= '                    <td>Reserve</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '            </tbody></table>'."\n";
$code .= '            <table border="1" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr style="font-weight:bold;background-color:#666;color:#fff;">'."\n";
$code .= '                    <td style="padding: 5px;">Product</td>'."\n";
$code .= '                    <td style="padding: 5px 10px;">Price (Baht)</td>'."\n";
$code .= '                    <td style="padding: 5px 10px;">Qty</td>'."\n";
$code .= '                    <td style="padding: 5px 10px;">Amount (Baht)</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                '."\n";

if(count($arraysuborder))
{
foreach($arraysuborder as $valusuborder)
{

if($valusuborder['discount']=='0')
{
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;">'."\n";
$code .= '                        <span style="font-weight:bold;display:block;"><a href="'.baseinfo.'/post/'.$valusuborder['productid'].'">'.$valusuborder['title'].'</a></span>'."\n";
//$code .= '                        <span>Main Attribute : Sub Attribute</span>'."\n";
$code .= '                    </td>'."\n";
$code .= '                    <td style="padding: 5px 10px;text-align:center;">'.$valusuborder['price'].'</td>'."\n";
$code .= '                    <td style="padding: 5px 10px;text-align:center;">'.$valusuborder['count'].'</td>'."\n";
$code .= '                    <td style="padding: 5px 10px;text-align:center;">'.(intval($valusuborder['count'])*intval($valusuborder['count'])).'</td>'."\n";
$code .= '                </tr>'."\n";
}

}
}

if(count($arraysuborder))
{
foreach($arraysuborder as $valusuborder)
{

if($valusuborder['price']=='0')
{
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;" colspan="3">'."\n";
$code .= '                        <span>'.$valusuborder['title'].'</span>'."\n";
$code .= '                    </td>'."\n";
$code .= '                    <td style="padding: 5px;text-align:center;">-'.$valusuborder['discount'].'</td>'."\n";
$code .= '                </tr>'."\n";
}
}
}




if($arrayproduct['tspoid'])
{
$sql='select * from tb_product_transport where tb_product_transport.tspoid='.$arrayproduct['tspoid'];
$arraytransport=$this->db->db_set_1recordrow($sql);

if($arraytransport['tspoid'])
{
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;" colspan="3">'."\n";
$code .= '                        <span style="font-weight:bold;">วิธีรับสินค้า : </span>'."\n";
$code .= '                        <span>'.$arraytransport['tspoid'].'</span>'."\n";
$code .= '                    </td>'."\n";
$code .= '                    <td style="padding: 5px;text-align:center;">'.$arraytransport['tspcost'].'</td>'."\n";
$code .= '                </tr>'."\n";
}

}

$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;font-size:20px;" colspan="3">'."\n";
$code .= '                        <span style="font-weight:bold;text-align:right;display:block;">Total</span>'."\n";
$code .= '                    </td>'."\n";
$code .= '                    <td style="padding: 5px;text-align:center;font-weight:bold;font-size:20px;">'.$arrayproduct['sumall'].'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '            </tbody></table>'."\n";
$code .= '            <table border="1" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr>'."\n";
$code .= '                    <td style="font-weight:bold;background-color:#666;color:#fff;padding: 5px;" colspan="4">Shipping Information</td>'."\n";
$code .= '                </tr>'."\n";

$sql='SELECT
tb_user.userid,
tb_user.shop,
tb_user.uuid,
tb_user.facebookid,
tb_user.oauth,
tb_user.badge,
tb_user.roleid,
tb_user.coimgid,
tb_user.imgmid,
tb_user.simgmid,
tb_user.bannerimgmid,
tb_user.sbannerimgmid,
tb_user.langid,
tb_user.statusalert,
tb_user.statussound,
tb_user.statusvibration,
tb_user.publish,
tb_user.post,
tb_user.emailcontact,
tb_user.myfacebook,
tb_user.autofacebook,
tb_user.mytwitter,
tb_user.autotwitter,
tb_user.mygoogleplus,
tb_user.autogoogleplus,
tb_user.`status`,
tb_user.username,
tb_user.firstname,
tb_user.lastname,
tb_user.description,
tb_user.displayname,
tb_user.`password`,
tb_user.email,
tb_user.emailfacebook,
tb_user.gender,
tb_user.lat,
tb_user.lng,
tb_user.birthdate,
tb_user.address,
tb_user.countryid,
tb_user.proid,
tb_user.disid,
tb_user.space,
tb_user.tumid,
tb_user.forgetcode,
tb_user.`code`,
tb_user.state,
tb_user.sameaddress,
tb_user.shipaddress,
tb_user.shipcountryid,
tb_user.shipproid,
tb_user.shipdisid,
tb_user.shiptumid,
tb_user.shipstate,
tb_user.shipcode,
tb_user.facebook,
tb_user.twitter,
tb_user.googleplus,
tb_user.website,
tb_user.phone,
tb_user.fax,
tb_user.createdate,
tb_user.etc,
tb_user.syncfacebook,
tb_user.syncuser,
tb_user.readsync,
tb_district.disname,
tb_tumbon.tumname,
tb_province.proname
FROM
tb_user
LEFT JOIN tb_district ON tb_user.shipdisid = tb_district.disid
LEFT JOIN tb_tumbon ON tb_user.shiptumid = tb_tumbon.tumid
LEFT JOIN tb_province ON tb_user.shipproid = tb_province.proid where tb_user.userid='.$arrayproduct['userid'];
$arraycustomer=$this->db->db_set_1recordrow($sql);

$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;padding: 5px;">Name :</td>'."\n";
$code .= '                    <td style="padding: 5px;">'.$arraycustomer['displayname'].'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;padding: 5px;">Email :</td>'."\n";
$code .= '                    <td style="padding: 5px;">'.$arraycustomer['emailcontact'].'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;padding: 5px;">Tel :</td>'."\n";
$code .= '                    <td style="padding: 5px;">'.$arraycustomer['phone'].'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;padding: 5px;">Address :</td>'."\n";
$strtext='';
if($arraycustomer['shipcountryid']=='210')
{



$strtext=$arraycustomer['disname'].' '.$arraycustomer['tumname'].' '.$arraycustomer['proname'].' '.$arraycustomer['shipcode'];

}else
{

$strtext=$arraycustomer['shipstate'].' '.$arraycustomer['shipcode'];

}

$code .= '                    <td style="padding: 5px;">'.$arraycustomer['address'].' '.$strtext.'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '            </tbody></table>'."\n";
$code .= '            <table border="0" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr>'."\n";
$code .= '                    <td style="font-weight:bold;background-color:#666;color:#fff;padding: 5px;" colspan="4">More Information</td>'."\n";
$code .= '                </tr>'."\n";

//$code .= '                <tr>'."\n";
//$code .= '                    <td style="padding: 5px;">Bla Bla Bla</td>'."\n";
//$code .= '                </tr>'."\n";

$code .= '            </tbody></table>'."\n";
$code .= '            <table border="0" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr>'."\n";
$code .= '                    <td style="font-weight:bold;background-color:#666;color:#fff;padding: 5px;" colspan="4">How to Pay</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;">No payment channel, contact the shop about the details of payment.</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;">'."\n";
$code .= '                        <div style="font-weight:bold;">1. Transfer</div>'."\n";
$code .= '                    </td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;">'."\n";
$code .= '                        <table border="1" cellspacing="0" cellpadding="0" style="margin-left:20px;">'."\n";
$code .= '                            <tbody><tr style="font-weight:bold;background-color:#999;color:#fff;text-align:center;">'."\n";
$code .= '                                <td style="padding: 5px">Bank</td>'."\n";
$code .= '                                <td style="padding: 5px">Branch</td>'."\n";
$code .= '                                <td style="padding: 5px">Number</td>'."\n";
$code .= '                                <td style="padding: 5px">Type</td>'."\n";
$code .= '                                <td style="padding: 5px">Name</td>'."\n";
$code .= '                            </tr>'."\n";


$sql='SELECT
tb_product_transfer_bank.bankname,
tb_product_transfer_type.typename,
tb_product_transfer.branch,
tb_product_transfer.accname,
tb_product_transfer.accnumber,
tb_product_transfer.tfid
FROM
tb_product_transfer
INNER JOIN tb_product_transfer_bank ON tb_product_transfer.bankid = tb_product_transfer_bank.bankid
INNER JOIN tb_product_transfer_type ON tb_product_transfer.actypeid = tb_product_transfer_type.actypeid
where tb_product_transfer.createby='.$arrayproduct['createby'].'
';

$arraytranferdata=$this->db->db_set_recordset($sql);


if(count($arraytranferdata))
{
foreach($arraytranferdata as $valuetranfer)
{
$code .= '                            <tr>'."\n";
$code .= '                                <td style="padding: 5px 10px;text-align:center;">'.$valuetranfer['bankname'].'</td>'."\n";
$code .= '                                <td style="padding: 5px 10px;text-align:center;">'.$valuetranfer['branch'].'</td>'."\n";
$code .= '                                <td style="padding: 5px 10px;text-align:center;">'.$valuetranfer['accnumber'].'</td>'."\n";
$code .= '                                <td style="padding: 5px 10px;text-align:center;">'.$valuetranfer['typename'].'</td>'."\n";
$code .= '                                <td style="padding: 5px 10px;text-align:center;">'.$valuetranfer['accname'].'</td>'."\n";
$code .= '                            </tr>'."\n";
}
}


$code .= '                        </tbody></table>'."\n";
$code .= '                    </td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                    <tr><td style="padding: 5px;"><a style="margin-left:20px;" href="">แจ้งชำระเงิน</a></td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '            </tbody></table>'."\n";
$code .= '        </td>'."\n";
$code .= '    </tr>'."\n";
$code .= '</tbody></table>  '."\n";
$code .= "\n";
$code .= "\n";
$code .= '</body></html>';


            require_once(pluginpath.'/phpmailer/class.config.php'); // uri
           
           $mail = new ConfigMail();
           //$mail->setFrom("s_chanyut@hotmail.com","Bird Kung");
           $mail->setTo($arraycustomer['emailcontact'],$arraycustomer['displayname']);
           $mail->setContent($code);
           $mail->setSubject("ทางร้านได้รับยอดเงินเรียบร้อยแล้ว");
           $mail->sendTo();
           
           
           
         //  $code=str_replace('คุณได้ทำรายการสั่งซื้อสินค้า',',มีลูกค้าทำรายการการสั่งซื้อ',$code);
//           
//           $mail->setClearAddress();
//           $mail->setTo($arraysetting['email'],$arraysetting['displayname']);
//           $mail->setContent($code);
//           $mail->setSubject("มีคนทำรายการสั่งซื้อสินค้า");
//           
//           
           
            
            
            }
            
            
             
            
            function sendemailshipbyorderid($orderid)
            {
            
            
            $sql='SELECT * FROM `tb_product_order` where tb_product_order.orderid='.$orderid;
            $arrayproduct=$this->db->db_set_1recordrow($sql);
            
            
            $sql='select 
IF (tb_product_setting.shopname is NULL,tb_user.displayname,tb_product_setting.shopname) as displayname,
tb_user.username,
IF (tb_product_setting.orderprefix is NULL,\'\',tb_product_setting.orderprefix) as orderprefix,
IF (tb_user.email,tb_user.email,tb_user.emailfacebook) as email

 from tb_user 

 LEFT JOIN tb_product_setting ON tb_user.userid = tb_product_setting.createby

 where tb_user.userid='.$arrayproduct['createby'];
            $arraysetting=$this->db->db_set_1recordrow($sql);
            
            
            $sql='SELECT
tb_product_suborder.suborderid,
tb_product_suborder.productid,
tb_product_suborder.credit,
tb_product_suborder.point,
tb_product_suborder.count,
tb_product_suborder.`delete`,
tb_product_suborder.orderid,
tb_product_suborder.title,
tb_product_suborder.note,
tb_product_suborder.discount,
tb_product_suborder.price,
tb_product.title
FROM
tb_product_suborder
INNER JOIN tb_product ON tb_product_suborder.productid = tb_product.productid  where tb_product_suborder.orderid='.$orderid;
            $arraysuborder=$this->db->db_set_recordset($sql);
            
            
            
           $code  = '<html xmlns="http://www.w3.org/1999/xhtml"><head>'."\n";
$code .= '    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">'."\n";
$code .= '    <meta content="width=device-width, initial-scale=1.0" name="viewport">'."\n";
$code .= '    <title>Order Information</title>'."\n";
$code .= '    <style type="text/css">'."\n";
$code .= '        #outlook a {padding:0;}'."\n";
$code .= '        body{width:100% !important; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%; margin:0; padding:0;} '."\n";
$code .= '        .ExternalClass {width:100%;} '."\n";
$code .= '        .ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {line-height: 100%;}'."\n";
$code .= '        #backgroundTable {margin:0; padding:0; width:100% !important; line-height: 100% !important;}'."\n";
$code .= '        img {outline:none; text-decoration:none; -ms-interpolation-mode: bicubic;} '."\n";
$code .= '        a img {border:none;} '."\n";
$code .= '        .image_fix {display:block;}'."\n";
$code .= '        p {margin: 1em 0;}'."\n";
$code .= '        h1, h2, h3, h4, h5, h6 {color: black !important;}'."\n";
$code .= '        h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {color: blue !important;}'."\n";
$code .= '        h1 a:active, h2 a:active,  h3 a:active, h4 a:active, h5 a:active, h6 a:active {'."\n";
$code .= '        color: red !important;'."\n";
$code .= '        }'."\n";
$code .= '        h1 a:visited, h2 a:visited,  h3 a:visited, h4 a:visited, h5 a:visited, h6 a:visited {'."\n";
$code .= '        color: purple !important;'."\n";
$code .= '        }'."\n";
$code .= '        table td {border-collapse: collapse;}'."\n";
$code .= '        table { border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; }'."\n";
$code .= '        a {color: orange;}'."\n";
$code .= '        @media only screen and (max-device-width: 480px) {'."\n";
$code .= '            a[href^="tel"], a[href^="sms"] {'."\n";
$code .= '                        text-decoration: none;'."\n";
$code .= '                        color: blue;'."\n";
$code .= '                        pointer-events: none;'."\n";
$code .= '                        cursor: default;'."\n";
$code .= '                    }'."\n";
$code .= "\n";
$code .= '            .mobile_link a[href^="tel"], .mobile_link a[href^="sms"] {'."\n";
$code .= '                        text-decoration: default;'."\n";
$code .= '                        color: orange !important;'."\n";
$code .= '                        pointer-events: auto;'."\n";
$code .= '                        cursor: default;'."\n";
$code .= '                    }'."\n";
$code .= "\n";
$code .= '        }'."\n";
$code .= '        @media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {'."\n";
$code .= '            a[href^="tel"], a[href^="sms"] {'."\n";
$code .= '                        text-decoration: none;'."\n";
$code .= '                        color: blue;'."\n";
$code .= '                        pointer-events: none;'."\n";
$code .= '                        cursor: default;'."\n";
$code .= '                    }'."\n";
$code .= "\n";
$code .= '            .mobile_link a[href^="tel"], .mobile_link a[href^="sms"] {'."\n";
$code .= '                        text-decoration: default;'."\n";
$code .= '                        color: orange !important;'."\n";
$code .= '                        pointer-events: auto;'."\n";
$code .= '                        cursor: default;'."\n";
$code .= '                    }'."\n";
$code .= '        }'."\n";
$code .= '        @media only screen and (-webkit-min-device-pixel-ratio: 2) {}'."\n";
$code .= '        @media only screen and (-webkit-device-pixel-ratio:.75){}'."\n";
$code .= '        @media only screen and (-webkit-device-pixel-ratio:1){}'."\n";
$code .= '        @media only screen and (-webkit-device-pixel-ratio:1.5){}'."\n";
$code .= '    </style>'."\n";
$code .= '</head>'."\n";
$code .= '<body>'."\n";






$code .= '<table border="0" cellspacing="0" cellpadding="0" style="font-family: Arial, Helvetica, sans-serif;min-width:320px;font-size:16px;" id="backgroundTable">'."\n";
$code .= '    <tbody><tr>'."\n";
$code .= '        <td valign="top" style="padding:20px;line-height:20px;">'."\n";




$code .= '<table border="0" cellspacing="0" cellpadding="0" style="margin-bottom:20px">'."\n";
$code .= '<tbody><tr style="height:80px;font-size:20px">'."\n";
$code .= '<td colspan="2">ทางร้านได้จัดส่งสินค้าให้ท่านแล้ว</td>'."\n";
$code .= '</tr>'."\n";


$sql='SELECT * FROM `tb_product_shipping` where orderid='.$orderid;
$arrayshipping=$this->db->db_set_1recordrow($sql);

if($arrayshipping['pshipid'])
{
$code .='<tr>
                    <td style="font-weight:bold;">รหัสพัสดุ :</td>
                    <td>'.$arrayshipping['code'].'</td>
                </tr>';

                $code .='<tr style="height:80px;font-size:20px">
                    <td style="font-weight:bold;">Note :</td>
                    <td>'.$arrayshipping['note'].'</td>
                </tr>';
}

$code .= '</tbody></table>';



$code .= '            <table border="0" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr>'."\n";
$code .= '                    <td style="font-weight:bold;">Shop :</td>'."\n";



$code .= '                    <td><a href="'.baseinfo.'/'.$arraysetting['username'].'">'.$arraysetting['displayname'].'</a></td>'."\n";


$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;">Order ID :</td>'."\n";
$code .= '                    <td><a href="">'.$arraysetting['orderprefix'].''.$arrayproduct['orderid'].'</a></td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";

$code .= '                    <td style="font-weight:bold;">Order On :</td>'."\n";
$code .= '                    <td>'.date('d/m/d H:i:s',strtotime($arrayproduct['createdate'])) .'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;">Status :</td>'."\n";
$code .= '                    <td>Reserve</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '            </tbody></table>'."\n";
$code .= '            <table border="1" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr style="font-weight:bold;background-color:#666;color:#fff;">'."\n";
$code .= '                    <td style="padding: 5px;">Product</td>'."\n";
$code .= '                    <td style="padding: 5px 10px;">Price (Baht)</td>'."\n";
$code .= '                    <td style="padding: 5px 10px;">Qty</td>'."\n";
$code .= '                    <td style="padding: 5px 10px;">Amount (Baht)</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                '."\n";

if(count($arraysuborder))
{
foreach($arraysuborder as $valusuborder)
{

if($valusuborder['discount']=='0')
{
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;">'."\n";
$code .= '                        <span style="font-weight:bold;display:block;"><a href="'.baseinfo.'/post/'.$valusuborder['productid'].'">'.$valusuborder['title'].'</a></span>'."\n";
//$code .= '                        <span>Main Attribute : Sub Attribute</span>'."\n";
$code .= '                    </td>'."\n";
$code .= '                    <td style="padding: 5px 10px;text-align:center;">'.$valusuborder['price'].'</td>'."\n";
$code .= '                    <td style="padding: 5px 10px;text-align:center;">'.$valusuborder['count'].'</td>'."\n";
$code .= '                    <td style="padding: 5px 10px;text-align:center;">'.(intval($valusuborder['count'])*intval($valusuborder['count'])).'</td>'."\n";
$code .= '                </tr>'."\n";
}

}
}

if(count($arraysuborder))
{
foreach($arraysuborder as $valusuborder)
{

if($valusuborder['price']=='0')
{
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;" colspan="3">'."\n";
$code .= '                        <span>'.$valusuborder['title'].'</span>'."\n";
$code .= '                    </td>'."\n";
$code .= '                    <td style="padding: 5px;text-align:center;">-'.$valusuborder['discount'].'</td>'."\n";
$code .= '                </tr>'."\n";
}
}
}




if($arrayproduct['tspoid'])
{
$sql='select * from tb_product_transport where tb_product_transport.tspoid='.$arrayproduct['tspoid'];
$arraytransport=$this->db->db_set_1recordrow($sql);

if($arraytransport['tspoid'])
{
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;" colspan="3">'."\n";
$code .= '                        <span style="font-weight:bold;">วิธีรับสินค้า : </span>'."\n";
$code .= '                        <span>'.$arraytransport['tspoid'].'</span>'."\n";
$code .= '                    </td>'."\n";
$code .= '                    <td style="padding: 5px;text-align:center;">'.$arraytransport['tspcost'].'</td>'."\n";
$code .= '                </tr>'."\n";
}

}

$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;font-size:20px;" colspan="3">'."\n";
$code .= '                        <span style="font-weight:bold;text-align:right;display:block;">Total</span>'."\n";
$code .= '                    </td>'."\n";
$code .= '                    <td style="padding: 5px;text-align:center;font-weight:bold;font-size:20px;">'.$arrayproduct['sumall'].'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '            </tbody></table>'."\n";
$code .= '            <table border="1" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr>'."\n";
$code .= '                    <td style="font-weight:bold;background-color:#666;color:#fff;padding: 5px;" colspan="4">Shipping Information</td>'."\n";
$code .= '                </tr>'."\n";

$sql='SELECT
tb_user.userid,
tb_user.shop,
tb_user.uuid,
tb_user.facebookid,
tb_user.oauth,
tb_user.badge,
tb_user.roleid,
tb_user.coimgid,
tb_user.imgmid,
tb_user.simgmid,
tb_user.bannerimgmid,
tb_user.sbannerimgmid,
tb_user.langid,
tb_user.statusalert,
tb_user.statussound,
tb_user.statusvibration,
tb_user.publish,
tb_user.post,
tb_user.emailcontact,
tb_user.myfacebook,
tb_user.autofacebook,
tb_user.mytwitter,
tb_user.autotwitter,
tb_user.mygoogleplus,
tb_user.autogoogleplus,
tb_user.`status`,
tb_user.username,
tb_user.firstname,
tb_user.lastname,
tb_user.description,
tb_user.displayname,
tb_user.`password`,
tb_user.email,
tb_user.emailfacebook,
tb_user.gender,
tb_user.lat,
tb_user.lng,
tb_user.birthdate,
tb_user.address,
tb_user.countryid,
tb_user.proid,
tb_user.disid,
tb_user.space,
tb_user.tumid,
tb_user.forgetcode,
tb_user.`code`,
tb_user.state,
tb_user.sameaddress,
tb_user.shipaddress,
tb_user.shipcountryid,
tb_user.shipproid,
tb_user.shipdisid,
tb_user.shiptumid,
tb_user.shipstate,
tb_user.shipcode,
tb_user.facebook,
tb_user.twitter,
tb_user.googleplus,
tb_user.website,
tb_user.phone,
tb_user.fax,
tb_user.createdate,
tb_user.etc,
tb_user.syncfacebook,
tb_user.syncuser,
tb_user.readsync,
tb_district.disname,
tb_tumbon.tumname,
tb_province.proname
FROM
tb_user
LEFT JOIN tb_district ON tb_user.shipdisid = tb_district.disid
LEFT JOIN tb_tumbon ON tb_user.shiptumid = tb_tumbon.tumid
LEFT JOIN tb_province ON tb_user.shipproid = tb_province.proid where tb_user.userid='.$arrayproduct['userid'];
$arraycustomer=$this->db->db_set_1recordrow($sql);

$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;padding: 5px;">Name :</td>'."\n";
$code .= '                    <td style="padding: 5px;">'.$arraycustomer['displayname'].'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;padding: 5px;">Email :</td>'."\n";
$code .= '                    <td style="padding: 5px;">'.$arraycustomer['emailcontact'].'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;padding: 5px;">Tel :</td>'."\n";
$code .= '                    <td style="padding: 5px;">'.$arraycustomer['phone'].'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;padding: 5px;">Address :</td>'."\n";
$strtext='';
if($arraycustomer['shipcountryid']=='210')
{



$strtext=$arraycustomer['disname'].' '.$arraycustomer['tumname'].' '.$arraycustomer['proname'].' '.$arraycustomer['shipcode'];

}else
{

$strtext=$arraycustomer['shipstate'].' '.$arraycustomer['shipcode'];

}

$code .= '                    <td style="padding: 5px;">'.$arraycustomer['address'].' '.$strtext.'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '            </tbody></table>'."\n";
$code .= '            <table border="0" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr>'."\n";
$code .= '                    <td style="font-weight:bold;background-color:#666;color:#fff;padding: 5px;" colspan="4">More Information</td>'."\n";
$code .= '                </tr>'."\n";

//$code .= '                <tr>'."\n";
//$code .= '                    <td style="padding: 5px;">Bla Bla Bla</td>'."\n";
//$code .= '                </tr>'."\n";

$code .= '            </tbody></table>'."\n";
$code .= '            <table border="0" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr>'."\n";
$code .= '                    <td style="font-weight:bold;background-color:#666;color:#fff;padding: 5px;" colspan="4">How to Pay</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;">No payment channel, contact the shop about the details of payment.</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;">'."\n";
$code .= '                        <div style="font-weight:bold;">1. Transfer</div>'."\n";
$code .= '                    </td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;">'."\n";
$code .= '                        <table border="1" cellspacing="0" cellpadding="0" style="margin-left:20px;">'."\n";
$code .= '                            <tbody><tr style="font-weight:bold;background-color:#999;color:#fff;text-align:center;">'."\n";
$code .= '                                <td style="padding: 5px">Bank</td>'."\n";
$code .= '                                <td style="padding: 5px">Branch</td>'."\n";
$code .= '                                <td style="padding: 5px">Number</td>'."\n";
$code .= '                                <td style="padding: 5px">Type</td>'."\n";
$code .= '                                <td style="padding: 5px">Name</td>'."\n";
$code .= '                            </tr>'."\n";


$sql='SELECT
tb_product_transfer_bank.bankname,
tb_product_transfer_type.typename,
tb_product_transfer.branch,
tb_product_transfer.accname,
tb_product_transfer.accnumber,
tb_product_transfer.tfid
FROM
tb_product_transfer
INNER JOIN tb_product_transfer_bank ON tb_product_transfer.bankid = tb_product_transfer_bank.bankid
INNER JOIN tb_product_transfer_type ON tb_product_transfer.actypeid = tb_product_transfer_type.actypeid
where tb_product_transfer.createby='.$arrayproduct['createby'].'
';

$arraytranferdata=$this->db->db_set_recordset($sql);


if(count($arraytranferdata))
{
foreach($arraytranferdata as $valuetranfer)
{
$code .= '                            <tr>'."\n";
$code .= '                                <td style="padding: 5px 10px;text-align:center;">'.$valuetranfer['bankname'].'</td>'."\n";
$code .= '                                <td style="padding: 5px 10px;text-align:center;">'.$valuetranfer['branch'].'</td>'."\n";
$code .= '                                <td style="padding: 5px 10px;text-align:center;">'.$valuetranfer['accnumber'].'</td>'."\n";
$code .= '                                <td style="padding: 5px 10px;text-align:center;">'.$valuetranfer['typename'].'</td>'."\n";
$code .= '                                <td style="padding: 5px 10px;text-align:center;">'.$valuetranfer['accname'].'</td>'."\n";
$code .= '                            </tr>'."\n";
}
}


$code .= '                        </tbody></table>'."\n";
$code .= '                    </td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                    <tr><td style="padding: 5px;"><a style="margin-left:20px;" href="">แจ้งชำระเงิน</a></td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '            </tbody></table>'."\n";
$code .= '        </td>'."\n";
$code .= '    </tr>'."\n";
$code .= '</tbody></table>  '."\n";
$code .= "\n";
$code .= "\n";
$code .= '</body></html>';


            require_once(pluginpath.'/phpmailer/class.config.php'); // uri
           
           $mail = new ConfigMail();
           //$mail->setFrom("s_chanyut@hotmail.com","Bird Kung");
           $mail->setTo($arraycustomer['emailcontact'],$arraycustomer['displayname']);
           $mail->setContent($code);
           $mail->setSubject("ทางร้านได้จัดส่งสินค้าให้ท่านแล้ว");
           $mail->sendTo();
           
           
           
         //  $code=str_replace('คุณได้ทำรายการสั่งซื้อสินค้า',',มีลูกค้าทำรายการการสั่งซื้อ',$code);
//           
//           $mail->setClearAddress();
//           $mail->setTo($arraysetting['email'],$arraysetting['displayname']);
//           $mail->setContent($code);
//           $mail->setSubject("มีคนทำรายการสั่งซื้อสินค้า");
//           
//           
           
            
            
            }
            
            
            
            
            function sendemailcancelbyorderid($orderid)
            {
            
            
            $sql='SELECT * FROM `tb_product_order` where tb_product_order.orderid='.$orderid;
            $arrayproduct=$this->db->db_set_1recordrow($sql);
            
            
            $sql='select 
IF (tb_product_setting.shopname is NULL,tb_user.displayname,tb_product_setting.shopname) as displayname,
tb_user.username,
IF (tb_product_setting.orderprefix is NULL,\'\',tb_product_setting.orderprefix) as orderprefix,
IF (tb_user.email,tb_user.email,tb_user.emailfacebook) as email

 from tb_user 

 LEFT JOIN tb_product_setting ON tb_user.userid = tb_product_setting.createby

 where tb_user.userid='.$arrayproduct['createby'];
            $arraysetting=$this->db->db_set_1recordrow($sql);
            
            
            $sql='SELECT
tb_product_suborder.suborderid,
tb_product_suborder.productid,
tb_product_suborder.credit,
tb_product_suborder.point,
tb_product_suborder.count,
tb_product_suborder.`delete`,
tb_product_suborder.orderid,
tb_product_suborder.title,
tb_product_suborder.note,
tb_product_suborder.discount,
tb_product_suborder.price,
tb_product.title
FROM
tb_product_suborder
INNER JOIN tb_product ON tb_product_suborder.productid = tb_product.productid  where tb_product_suborder.orderid='.$orderid;
            $arraysuborder=$this->db->db_set_recordset($sql);
            
            
            
           $code  = '<html xmlns="http://www.w3.org/1999/xhtml"><head>'."\n";
$code .= '    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">'."\n";
$code .= '    <meta content="width=device-width, initial-scale=1.0" name="viewport">'."\n";
$code .= '    <title>Order Information</title>'."\n";
$code .= '    <style type="text/css">'."\n";
$code .= '        #outlook a {padding:0;}'."\n";
$code .= '        body{width:100% !important; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%; margin:0; padding:0;} '."\n";
$code .= '        .ExternalClass {width:100%;} '."\n";
$code .= '        .ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {line-height: 100%;}'."\n";
$code .= '        #backgroundTable {margin:0; padding:0; width:100% !important; line-height: 100% !important;}'."\n";
$code .= '        img {outline:none; text-decoration:none; -ms-interpolation-mode: bicubic;} '."\n";
$code .= '        a img {border:none;} '."\n";
$code .= '        .image_fix {display:block;}'."\n";
$code .= '        p {margin: 1em 0;}'."\n";
$code .= '        h1, h2, h3, h4, h5, h6 {color: black !important;}'."\n";
$code .= '        h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {color: blue !important;}'."\n";
$code .= '        h1 a:active, h2 a:active,  h3 a:active, h4 a:active, h5 a:active, h6 a:active {'."\n";
$code .= '        color: red !important;'."\n";
$code .= '        }'."\n";
$code .= '        h1 a:visited, h2 a:visited,  h3 a:visited, h4 a:visited, h5 a:visited, h6 a:visited {'."\n";
$code .= '        color: purple !important;'."\n";
$code .= '        }'."\n";
$code .= '        table td {border-collapse: collapse;}'."\n";
$code .= '        table { border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; }'."\n";
$code .= '        a {color: orange;}'."\n";
$code .= '        @media only screen and (max-device-width: 480px) {'."\n";
$code .= '            a[href^="tel"], a[href^="sms"] {'."\n";
$code .= '                        text-decoration: none;'."\n";
$code .= '                        color: blue;'."\n";
$code .= '                        pointer-events: none;'."\n";
$code .= '                        cursor: default;'."\n";
$code .= '                    }'."\n";
$code .= "\n";
$code .= '            .mobile_link a[href^="tel"], .mobile_link a[href^="sms"] {'."\n";
$code .= '                        text-decoration: default;'."\n";
$code .= '                        color: orange !important;'."\n";
$code .= '                        pointer-events: auto;'."\n";
$code .= '                        cursor: default;'."\n";
$code .= '                    }'."\n";
$code .= "\n";
$code .= '        }'."\n";
$code .= '        @media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {'."\n";
$code .= '            a[href^="tel"], a[href^="sms"] {'."\n";
$code .= '                        text-decoration: none;'."\n";
$code .= '                        color: blue;'."\n";
$code .= '                        pointer-events: none;'."\n";
$code .= '                        cursor: default;'."\n";
$code .= '                    }'."\n";
$code .= "\n";
$code .= '            .mobile_link a[href^="tel"], .mobile_link a[href^="sms"] {'."\n";
$code .= '                        text-decoration: default;'."\n";
$code .= '                        color: orange !important;'."\n";
$code .= '                        pointer-events: auto;'."\n";
$code .= '                        cursor: default;'."\n";
$code .= '                    }'."\n";
$code .= '        }'."\n";
$code .= '        @media only screen and (-webkit-min-device-pixel-ratio: 2) {}'."\n";
$code .= '        @media only screen and (-webkit-device-pixel-ratio:.75){}'."\n";
$code .= '        @media only screen and (-webkit-device-pixel-ratio:1){}'."\n";
$code .= '        @media only screen and (-webkit-device-pixel-ratio:1.5){}'."\n";
$code .= '    </style>'."\n";
$code .= '</head>'."\n";
$code .= '<body>'."\n";






$code .= '<table border="0" cellspacing="0" cellpadding="0" style="font-family: Arial, Helvetica, sans-serif;min-width:320px;font-size:16px;" id="backgroundTable">'."\n";
$code .= '    <tbody><tr>'."\n";
$code .= '        <td valign="top" style="padding:20px;line-height:20px;">'."\n";

  


$code .= '<table border="0" cellspacing="0" cellpadding="0" style="margin-bottom:20px">'."\n";
$code .= '<tbody><tr style="height:80px;font-size:20px">'."\n";
$code .= '<td colspan="2">ยกเลิกรายการสั่งซื้อแล้ว</td>'."\n";
$code .= '</tr>'."\n";


$code .= '</tbody></table>';



$code .= '            <table border="0" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr>'."\n";
$code .= '                    <td style="font-weight:bold;">Shop :</td>'."\n";



$code .= '                    <td><a href="'.baseinfo.'/'.$arraysetting['username'].'">'.$arraysetting['displayname'].'</a></td>'."\n";


$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;">Order ID :</td>'."\n";
$code .= '                    <td><a href="">'.$arraysetting['orderprefix'].''.$arrayproduct['orderid'].'</a></td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";

$code .= '                    <td style="font-weight:bold;">Order On :</td>'."\n";
$code .= '                    <td>'.date('d/m/d H:i:s',strtotime($arrayproduct['createdate'])) .'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;">Status :</td>'."\n";
$code .= '                    <td>Reserve</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '            </tbody></table>'."\n";
$code .= '            <table border="1" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr style="font-weight:bold;background-color:#666;color:#fff;">'."\n";
$code .= '                    <td style="padding: 5px;">Product</td>'."\n";
$code .= '                    <td style="padding: 5px 10px;">Price (Baht)</td>'."\n";
$code .= '                    <td style="padding: 5px 10px;">Qty</td>'."\n";
$code .= '                    <td style="padding: 5px 10px;">Amount (Baht)</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                '."\n";

if(count($arraysuborder))
{
foreach($arraysuborder as $valusuborder)
{

if($valusuborder['discount']=='0')
{
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;">'."\n";
$code .= '                        <span style="font-weight:bold;display:block;"><a href="'.baseinfo.'/post/'.$valusuborder['productid'].'">'.$valusuborder['title'].'</a></span>'."\n";
//$code .= '                        <span>Main Attribute : Sub Attribute</span>'."\n";
$code .= '                    </td>'."\n";
$code .= '                    <td style="padding: 5px 10px;text-align:center;">'.$valusuborder['price'].'</td>'."\n";
$code .= '                    <td style="padding: 5px 10px;text-align:center;">'.$valusuborder['count'].'</td>'."\n";
$code .= '                    <td style="padding: 5px 10px;text-align:center;">'.(intval($valusuborder['count'])*intval($valusuborder['count'])).'</td>'."\n";
$code .= '                </tr>'."\n";
}

}
}

if(count($arraysuborder))
{
foreach($arraysuborder as $valusuborder)
{

if($valusuborder['price']=='0')
{
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;" colspan="3">'."\n";
$code .= '                        <span>'.$valusuborder['title'].'</span>'."\n";
$code .= '                    </td>'."\n";
$code .= '                    <td style="padding: 5px;text-align:center;">-'.$valusuborder['discount'].'</td>'."\n";
$code .= '                </tr>'."\n";
}
}
}




if($arrayproduct['tspoid'])
{
$sql='select * from tb_product_transport where tb_product_transport.tspoid='.$arrayproduct['tspoid'];
$arraytransport=$this->db->db_set_1recordrow($sql);

if($arraytransport['tspoid'])
{
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;" colspan="3">'."\n";
$code .= '                        <span style="font-weight:bold;">วิธีรับสินค้า : </span>'."\n";
$code .= '                        <span>'.$arraytransport['tspoid'].'</span>'."\n";
$code .= '                    </td>'."\n";
$code .= '                    <td style="padding: 5px;text-align:center;">'.$arraytransport['tspcost'].'</td>'."\n";
$code .= '                </tr>'."\n";
}

}

$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;font-size:20px;" colspan="3">'."\n";
$code .= '                        <span style="font-weight:bold;text-align:right;display:block;">Total</span>'."\n";
$code .= '                    </td>'."\n";
$code .= '                    <td style="padding: 5px;text-align:center;font-weight:bold;font-size:20px;">'.$arrayproduct['sumall'].'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '            </tbody></table>'."\n";
$code .= '            <table border="1" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr>'."\n";
$code .= '                    <td style="font-weight:bold;background-color:#666;color:#fff;padding: 5px;" colspan="4">Shipping Information</td>'."\n";
$code .= '                </tr>'."\n";

$sql='SELECT
tb_user.userid,
tb_user.shop,
tb_user.uuid,
tb_user.facebookid,
tb_user.oauth,
tb_user.badge,
tb_user.roleid,
tb_user.coimgid,
tb_user.imgmid,
tb_user.simgmid,
tb_user.bannerimgmid,
tb_user.sbannerimgmid,
tb_user.langid,
tb_user.statusalert,
tb_user.statussound,
tb_user.statusvibration,
tb_user.publish,
tb_user.post,
tb_user.emailcontact,
tb_user.myfacebook,
tb_user.autofacebook,
tb_user.mytwitter,
tb_user.autotwitter,
tb_user.mygoogleplus,
tb_user.autogoogleplus,
tb_user.`status`,
tb_user.username,
tb_user.firstname,
tb_user.lastname,
tb_user.description,
tb_user.displayname,
tb_user.`password`,
tb_user.email,
tb_user.emailfacebook,
tb_user.gender,
tb_user.lat,
tb_user.lng,
tb_user.birthdate,
tb_user.address,
tb_user.countryid,
tb_user.proid,
tb_user.disid,
tb_user.space,
tb_user.tumid,
tb_user.forgetcode,
tb_user.`code`,
tb_user.state,
tb_user.sameaddress,
tb_user.shipaddress,
tb_user.shipcountryid,
tb_user.shipproid,
tb_user.shipdisid,
tb_user.shiptumid,
tb_user.shipstate,
tb_user.shipcode,
tb_user.facebook,
tb_user.twitter,
tb_user.googleplus,
tb_user.website,
tb_user.phone,
tb_user.fax,
tb_user.createdate,
tb_user.etc,
tb_user.syncfacebook,
tb_user.syncuser,
tb_user.readsync,
tb_district.disname,
tb_tumbon.tumname,
tb_province.proname
FROM
tb_user
LEFT JOIN tb_district ON tb_user.shipdisid = tb_district.disid
LEFT JOIN tb_tumbon ON tb_user.shiptumid = tb_tumbon.tumid
LEFT JOIN tb_province ON tb_user.shipproid = tb_province.proid where tb_user.userid='.$arrayproduct['userid'];
$arraycustomer=$this->db->db_set_1recordrow($sql);

$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;padding: 5px;">Name :</td>'."\n";
$code .= '                    <td style="padding: 5px;">'.$arraycustomer['displayname'].'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;padding: 5px;">Email :</td>'."\n";
$code .= '                    <td style="padding: 5px;">'.$arraycustomer['emailcontact'].'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;padding: 5px;">Tel :</td>'."\n";
$code .= '                    <td style="padding: 5px;">'.$arraycustomer['phone'].'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="font-weight:bold;padding: 5px;">Address :</td>'."\n";
$strtext='';
if($arraycustomer['shipcountryid']=='210')
{



$strtext=$arraycustomer['disname'].' '.$arraycustomer['tumname'].' '.$arraycustomer['proname'].' '.$arraycustomer['shipcode'];

}else
{

$strtext=$arraycustomer['shipstate'].' '.$arraycustomer['shipcode'];

}

$code .= '                    <td style="padding: 5px;">'.$arraycustomer['address'].' '.$strtext.'</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '            </tbody></table>'."\n";
$code .= '            <table border="0" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr>'."\n";
$code .= '                    <td style="font-weight:bold;background-color:#666;color:#fff;padding: 5px;" colspan="4">More Information</td>'."\n";
$code .= '                </tr>'."\n";

//$code .= '                <tr>'."\n";
//$code .= '                    <td style="padding: 5px;">Bla Bla Bla</td>'."\n";
//$code .= '                </tr>'."\n";

$code .= '            </tbody></table>'."\n";
$code .= '            <table border="0" cellspacing="0" cellpadding="0" style="margin-bottom:20px;">'."\n";
$code .= '                <tbody><tr>'."\n";
$code .= '                    <td style="font-weight:bold;background-color:#666;color:#fff;padding: 5px;" colspan="4">How to Pay</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;">No payment channel, contact the shop about the details of payment.</td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;">'."\n";
$code .= '                        <div style="font-weight:bold;">1. Transfer</div>'."\n";
$code .= '                    </td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                <tr>'."\n";
$code .= '                    <td style="padding: 5px;">'."\n";
$code .= '                        <table border="1" cellspacing="0" cellpadding="0" style="margin-left:20px;">'."\n";
$code .= '                            <tbody><tr style="font-weight:bold;background-color:#999;color:#fff;text-align:center;">'."\n";
$code .= '                                <td style="padding: 5px">Bank</td>'."\n";
$code .= '                                <td style="padding: 5px">Branch</td>'."\n";
$code .= '                                <td style="padding: 5px">Number</td>'."\n";
$code .= '                                <td style="padding: 5px">Type</td>'."\n";
$code .= '                                <td style="padding: 5px">Name</td>'."\n";
$code .= '                            </tr>'."\n";


$sql='SELECT
tb_product_transfer_bank.bankname,
tb_product_transfer_type.typename,
tb_product_transfer.branch,
tb_product_transfer.accname,
tb_product_transfer.accnumber,
tb_product_transfer.tfid
FROM
tb_product_transfer
INNER JOIN tb_product_transfer_bank ON tb_product_transfer.bankid = tb_product_transfer_bank.bankid
INNER JOIN tb_product_transfer_type ON tb_product_transfer.actypeid = tb_product_transfer_type.actypeid
where tb_product_transfer.createby='.$arrayproduct['createby'].'
';

$arraytranferdata=$this->db->db_set_recordset($sql);


if(count($arraytranferdata))
{
foreach($arraytranferdata as $valuetranfer)
{
$code .= '                            <tr>'."\n";
$code .= '                                <td style="padding: 5px 10px;text-align:center;">'.$valuetranfer['bankname'].'</td>'."\n";
$code .= '                                <td style="padding: 5px 10px;text-align:center;">'.$valuetranfer['branch'].'</td>'."\n";
$code .= '                                <td style="padding: 5px 10px;text-align:center;">'.$valuetranfer['accnumber'].'</td>'."\n";
$code .= '                                <td style="padding: 5px 10px;text-align:center;">'.$valuetranfer['typename'].'</td>'."\n";
$code .= '                                <td style="padding: 5px 10px;text-align:center;">'.$valuetranfer['accname'].'</td>'."\n";
$code .= '                            </tr>'."\n";
}
}


$code .= '                        </tbody></table>'."\n";
$code .= '                    </td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                    <tr><td style="padding: 5px;"><a style="margin-left:20px;" href="">แจ้งชำระเงิน</a></td>'."\n";
$code .= '                </tr>'."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '                '."\n";
$code .= '            </tbody></table>'."\n";
$code .= '        </td>'."\n";
$code .= '    </tr>'."\n";
$code .= '</tbody></table>  '."\n";
$code .= "\n";
$code .= "\n";
$code .= '</body></html>';


            require_once(pluginpath.'/phpmailer/class.config.php'); // uri
           
           $mail = new ConfigMail();
           //$mail->setFrom("s_chanyut@hotmail.com","Bird Kung");
           $mail->setTo($arraycustomer['emailcontact'],$arraycustomer['displayname']);
           $mail->setContent($code);
           $mail->setSubject("ทางร้านได้รับยอดเงินเรียบร้อยแล้ว");
           $mail->sendTo();
           
           
           
         //  $code=str_replace('คุณได้ทำรายการสั่งซื้อสินค้า',',มีลูกค้าทำรายการการสั่งซื้อ',$code);
//           
//           $mail->setClearAddress();
//           $mail->setTo($arraysetting['email'],$arraysetting['displayname']);
//           $mail->setContent($code);
//           $mail->setSubject("มีคนทำรายการสั่งซื้อสินค้า");
//           
//           
           
            
            
            }
            
            
            function changeproductstock($qty,$productid,$cre=0)
            {
           
            
             $sql='select * from tb_plugins_pricefull where productid='.$productid;
            $arraydata=$this->db->db_set_1recordrow($sql);
            if($arraydata['unlimit']=='0')
            {
             if($cre)
            {
            $newamount=intval($arraydata['amount'])+intval($qty);
            }else
            {
           $newamount=intval($arraydata['amount'])-intval($qty);
            
            
            }
            $updateproduct=array();
            $updateproduct['amount']=$newamount;
            $this->db->db_set($updateproduct,'tb_plugins_pricefull',' productid='.$productid);
            
            }
            
            
            }
            
            
            function changepointstock($point,$userid,$cre=0)
            {
           
            
             $sql='select * from tb_game_score where userid='.$userid;
            $arraydata=$this->db->db_set_1recordrow($sql);
            if($arraydata['point'])
            {
             if($cre)
            {
            $newamount=intval($arraydata['point'])+intval($point);
            }else
            {
           $newamount=intval($arraydata['point'])-intval($point);
            
            
            }
            $updateproduct=array();
            $updateproduct['point']=$newamount;
            $this->db->db_set($updateproduct,'tb_game_score',' userid='.$userid);
            
            }
            
            
            }
            
            function getorderlistdatabyuserid($userid,$pagenow)
            {
            
             $page=(($pagenow - 1) * 20);
             $limit="limit  $page,20";
          $sql='SELECT
*,DATE_FORMAT(tb_product_order.createdate
,\'%d/%m/%Y\') newdate,DATE_FORMAT(tb_product_order.createdate
,\'%l:%i %p\') newtime
FROM
tb_product_order
where tb_product_order.`userid` = '.$userid.' and  tb_product_order.`status`=2
'.' order by tb_product_order.createdate desc '.$limit;

            $arraynewdata=array();
            $arraydata=$this->db->db_set_recordset($sql);
            if(count($arraydata))
            {$k=0;
            foreach($arraydata as $valuedata)
            {
            
            $sql='SELECT * FROM `tb_product_suborder` where orderid='.$valuedata['orderid'];
            $arraydata2=$this->db->db_set_recordset($sql);
            if(count($arraydata2))
            {
            $x=0;
            foreach($arraydata2 as $valuedata2)
            {
            if($valuedata2['productid'])
            {
            
            $sql='select title from tb_product where productid='.$valuedata2['productid'];
            
            $arrproduct=$this->db->db_set_1recordrow($sql);
            
            
        //    $arrproduct['img']=$this->getimagebyimgmid($arrproduct['imgmid']);
         //   $arrproduct['simg']=$this->getimagebyimgmid($arrproduct['simgmid']);
            
            $arraydata2[$x]['productlist']=$arrproduct;
            }else
            {
            $arraydata2[$x]['productlist']=array();
            
            }
            
            $x++;
            
            
            }
            
            }
            
            $arraydata[$k]['suborder']=$arraydata2;
            
            
            

            
            
            $k++;
            
            }
            
            }
            $arraynewdata=array();
            $arraynewdata['data']=$arraydata;
            if($pagenow==1)
            {
            $sql='select count(*) as countproduct from tb_product_order where tb_product_order.`userid` = '.$userid.' and tb_product_order.`status` = 2';
            
            $countdata=$this->db->db_set_1recordrow($sql);
            $arraynewdata['count']=intval($countdata['countproduct']);
            }else
            {
            $arraynewdata['count']=0;
            
            }
            
            return $arraynewdata;
            
            }
            
            function getproductdiscountdata()
            {
            
           
            
           $innerjoin=' INNER JOIN tb_plugins_discount ON tb_product.productid = tb_plugins_discount.productid ';
           $where=' where tb_product.delete=0 ';
           
            return $this->getproductbycondition($where,'','',$innerjoin,'','',1);

              //  $tagproduct=$this->db->db_set_recordset($sql);
               // return $tagproduct;
            
            }
            
            function getorderbyid($orderid)
            {
            $arraynewdata=array();
            $sql='select * from tb_product_order where orderid='.$orderid;
            $arraydata=$this->db->db_set_recordset($sql);
            
            if(count($arraydata))
            {
            $k=0;
            foreach($arraydata as $valuedata)
            {
            
            $sql='SELECT * FROM `tb_product_suborder` where orderid='.$valuedata['orderid'];
            $arraydata2=$this->db->db_set_recordset($sql);
            if(count($arraydata2))
            {
            $x=0;
            foreach($arraydata2 as $valuedata2)
            {
            if($valuedata2['productid'])
            {
            
            $sql='select title,simgmid,imgmid from tb_product where productid='.$valuedata2['productid'];
            
            $arrproduct=$this->db->db_set_1recordrow($sql);
            
            
            $arrproduct['img']=$this->getimagebyimgmid($arrproduct['imgmid']);
            $arrproduct['simg']=$this->getimagebyimgmid($arrproduct['simgmid']);
            
            $arraydata2[$x]['productlist']=$arrproduct;
            }else
            {
            $arraydata2[$x]['productlist']=array();
            
            }
            
            $x++;
            
            
            }
            
            }
            
            $arraydata[$k]['suborder']=$arraydata2;
            
            
            
            if($arraydata[$k]['userid']!='0')
            {
            $userdata=$this->getuserbyuserid($arraydata[$k]['userid']);
            
            $userdata2=$this->getuseralldata($userdata['oauth']);
            $arraydata[$k]['user']=$userdata2['userdata'];
            $arraydata[$k]['user']['credit']=$this->getcreditbyuserid($userdata2['userdata']['userid']);
            
            
            }else
            {
            $arraydata[$k]['user']=array();
            
            }
            
            
            $k++;
            
            }
            
            }
            $k=0;
            return $arraydata[$k];
            
            
            }
            
            
            function updatetimefollow($userid,$oauth)
            {
              
              $userdata=$this->getuserbyoauth($oauth);
              if($userid&&$userdata['userid'])
              {
              $sql="SELECT
                        tb_follow.foid
                        FROM
                        tb_follow
                        where ( tb_follow.createby=".$userid." and tb_follow.userid=".$userdata['userid']." ) or ( tb_follow.createby=".$userdata['userid']." and tb_follow.userid=".$userid." )
                        ";
              $datafollow=$this->db->db_set_recordset($sql);
              if(count($datafollow))
              {
              foreach($datafollow as $valuefollow)
              {
              $arraydatanow['updatedate']=date("Y-m-d H:i:s");
              $this->db->db_set($arraydatanow,'tb_follow',' foid='.$valuefollow['foid']);
              
              }
              
              }
              
              }
            
            
            }
            
             function setfollowother($userid,$oauth)
           {
            $arraydata=array();
            $userdata=$this->getuserbyoauth($oauth);
              if($userid&&$userdata['userid'])
              {
              $sql="SELECT
                        tb_follow.status,createby
                        FROM
                        tb_follow
                        where (( tb_follow.createby=".$userid." and tb_follow.userid=".$userdata['userid']." ) or ( tb_follow.createby=".$userdata['userid']." and tb_follow.userid=".$userid." ) ) 
                        ";
              

              $datafollow=$this->db->db_set_recordset($sql);
              if(count($datafollow))
              {
              foreach($datafollow as $valuedatafollow)
              {
              if($valuedatafollow['block']==1||$valuedatafollow['status']==3)
              {
              $status=0;
              }
              else if($valuedatafollow['status']==1)
              {
              $status=6;
              
              }else if($valuedatafollow['createby']==$userdata['userid'])
              {
              
              $status=2;
              break;
              
              }else if($valuedatafollow['createby']==$userid)
              {
              
              $status=1;
              break;
              
              }
              
              
              
              
              }
              
              }else
              {
              $arraydatanow['createby']=$userdata['userid'];
              $arraydatanow['userid']=$userid;
              $arraydatanow['status']=1;
              $arraydatanow['updateby']=$userdata['userid'];
              $arraydatanow['updatedate']=date("Y-m-d H:i:s");
              $arraydatanow['createdate']=date("Y-m-d H:i:s");
              $this->db->db_set($arraydatanow,'tb_follow');
              $status=6;
              
              
              }
              return $status;
              }
           
           }
           
            function checklastmsg($userid,$oauth,$msgid=0)
            {
            $msglid=$this->getmsglistid($userid,$oauth);
            $sql="select msgid from tb_msg where tb_msg.msglid=".$msglid.' and tb_msg.status=1 order by createdate desc limit 0,1';
            $datamsg=$this->db->db_set_1recordrow($sql);
            
            if($datamsg['msgid'])
            {
            $msgid2=intval($datamsg['msgid']);
            $msgid=intval($msgid);
            if($msgid2>$msgid)
            {
            
            return true;
            }else
            {
            
           return false; 
            }
            
            
            }else
            {
            
            return false;
            }
            
            
            
            }
            
            function getallmsglist($userid,$oauth,$page=1)
            {
            $page=(($page-1)*20);
            
            $msglid=$this->getmsglistid($userid,$oauth);
            
            $this->updatetimefollow($userid,$oauth);
            
            $datauser=$this->getuserbyuserid($userid);
            $datamyuser=$this->getuserbyoauth($oauth);
            
            
            
            $setarr=array();
            unset($datauser['oauth']);
            unset($datamyuser['oauth']);
            
            $datauser['imguser']=$this->getimagebyimgmid($datauser['imgmid']);
            $datauser['simgmid']=$this->getimagebyimgmid($datauser['simgmid']);
            $datamyuser['imguser']=$this->getimagebyimgmid($datamyuser['imgmid']);
            $datamyuser['simguser']=$this->getimagebyimgmid($datamyuser['simgmid']);
            
            
            $setarr[$userid]=$datauser;
            $setarr[$datamyuser['userid']]=$datamyuser;
            
            
            $sql="select * from tb_msg where tb_msg.msglid=".$msglid.' and tb_msg.status=1 order by createdate desc limit '.$page.',20';
            $datamsg=$this->db->db_set_recordset($sql);
            
            if(count($datamsg))
            {$k=0;
            foreach($datamsg as $valuemsg)
            {
            $datamsg[$k]['fromuser']=$setarr[$valuemsg['createby']];
            $datamsg[$k]['touser']=$setarr[$valuemsg['userid']];
            $datamsg[$k]['msgid']=$valuemsg['msgid'];
            $datamsg[$k]['msg']=stripcslashes($datamsg[$k]['msg']);
            
            $datamsg[$k]['newdate']=date("d/m/Y",strtotime($valuemsg['createdate'])) ;
            $datamsg[$k]['newdateid']=date("d-m-Y",strtotime($valuemsg['createdate'])) ;
            $datamsg[$k]['newtime']=date("g:i a",strtotime($valuemsg['createdate'])) ;
            
            $datamsg[$k]['imgarr']=array();
            if($valuemsg['imgmid'])
            {
            
            $datamsg[$k]['imgarr']=$this->getimagebyimgmid($valuemsg['imgmid']);
            
            }
            
            $k++;
            
            }
            
            }
            return $datamsg;
            
            }
            
            function encodetext($text)
            {
                        $string  = 'helloworld-'.$text.'-database64';
                        $encoded = base64_encode($string);
                        
                        $encoded=str_replace('==','',$encoded);
                        
                        
                        $encoded=base64_encode($encoded);
                        
                        
                        $encoded=str_replace('=','',$encoded);
                        
                        
                        //$compressed   = gzdeflate($encoded);
                      
                     
                        

                        return $encoded;
            }
            
            function decodetext($text)
            {
            
            
            
            
            $text=$text.'=';
            $decoded =  base64_decode($text);
            $decoded=$decoded.'==';
            $decoded =  base64_decode($decoded);
            
            
            
            
            list($t1,$text,$t2)=explode("-",$decoded);
            
            return $text;
            
            }
            
            function getgendername($gender)
            {
            switch ($gender) {
            
            case "0":
             
                return "";   
                break;
            case 1:
                return "Male";
                break;
            case 2:
                //  following
                return "Female";

                break;
         
            }
            
            
            }
            
            function savetoken($userid,$token,$uuid)
            {
            $sql="select tokenid from tb_token where tb_token.token='".$token."'";
            $tokenlist=$this->db->db_set_1recordrow($sql);
            $arraydata['userid']=$userid;
            $arraydata['uuid']=$uuid;
            $arraydata['updatedate']=date("Y-m-d H:i:s");
            $arraydata['status']=1;
            if($tokenlist['tokenid'])
            {
            
            $this->db->db_set($arraydata,'tb_token',' tb_token.tokenid='.$tokenlist['tokenid']);
            
            
            }else
            {
            $arraydata['token']=$token;
            
            $arraydata['createdate']=date("Y-m-d H:i:s");
            $this->db->db_set($arraydata,'tb_token');
            
            }
            
            
            }
            
            function deletetoken($token)
            {
            $sql="select tokenid from tb_token where tb_token.token='".$token."'";
            $tokenlist=$this->db->db_set_1recordrow($sql);
             if($tokenlist['tokenid'])
            {
            $arraydata['status']=0;
            $this->db->db_set($arraydata,'tb_token',' tb_token.tokenid='.$tokenlist['tokenid']);
            
            
            }
            
            
            }
            
            
            //start 2-09-2556
            
            function getproductbytagname($tagname,$limit=0,$row=9)
            {
            
            $search=str_replace("#",'',$tagname);
    
    $arraysearch=explode("#",$tagname);
    $where=array();
    if(count($arraysearch))
    {
     foreach($arraysearch as $valuesearch)
     {
     if($valuesearch)
     $where[]='tb_tag.`name` like "%'.trim($valuesearch).'%"';
     
     
     }
    
    }
    $wherestr='tb_tag.`name` like "%'.trim($search).'%"';
    if(count($where))
    {
     $wherestr=join(" or ",$where);
    
    }
    
    
    $sql='SELECT
    tb_product.*
    ,IF (tb_user.displayname = \'\', tb_user.username,tb_user.displayname) as displayname,tb_user.username,tb_user.imgmid as userimgmid,tb_user.simgmid as usersimgmid
    FROM
    tb_relate_tag
    INNER JOIN tb_tag ON tb_tag.tagid = tb_relate_tag.tagid
    INNER JOIN tb_product ON tb_relate_tag.productid = tb_product.productid
    inner join tb_user ON tb_user.userid=tb_product.createby  
    where tb_product.`delete`=0 and ('.$wherestr.') 
    
    GROUP BY tb_product.productid order by tb_product.createdate desc limit '.$limit.','.$row;
    
    
    
    

    
    $arrayproduct=$this->db->db_set_recordset($sql);
    $arrayplugin=array();
    if(count($arrayproduct))
    {
    foreach($arrayproduct as $valueproduct)
    {
    
    //if($valueproduct['imgmid'])
    $valueproduct['link']=str_replace(array("/"," ","?","&",";","#","'",'"'),"-",$valueproduct['link']);
     $valueproduct['img']= $this->getimagebyimgmid($valueproduct['imgmid']);
     $valueproduct['simg']= $this->getimagebyimgmid($valueproduct['simgmid']);
     
     $valueproduct['usersimg']= $this->getimagebyimgmid($valuedata['usersimgmid']);
     $valueproduct['userssimg']= $this->getimagebyimgmid($valuedata['usersimgmid']);
     
     
     $valueproduct['countlike']=$this->countfav($valueproduct['productid']);
   //  $valuedata['checklike']=  $this->checkuserlike($valueproduct['productid'],$this->userdata['oauth']); 
    
    
    $arrayplugin[]=$valueproduct;
    
    
    
    }
    
    
    }
    
    
    return $arrayplugin;
            
            
            }
            
            function countproductbytagname($tagname,$fid=0)
            {
            
            $search=str_replace("#",'',$tagname);
    
            $arraysearch=explode("#",$tagname);
            $where=array();
            if(count($arraysearch))
            {
             foreach($arraysearch as $valuesearch)
             {
             if($valuesearch)
             $where[]='tb_tag.`name` like "%'.trim($valuesearch).'%"';
             
             
             }
            
            }
            $wherestr='tb_tag.`name` like "%'.trim($search).'%"';
            if(count($where))
            {
             $wherestr=join(" or ",$where);
            
            }
            
            if($fid)
            {
            
               $wherestr.=' and tb_product.`fid` ='.$fid.' ';
               
            }
            
                $sql='SELECT
    count(tb_product.productid) as countproduct
    FROM
    tb_relate_tag
    INNER JOIN tb_tag ON tb_tag.tagid = tb_relate_tag.tagid
    INNER JOIN tb_product ON tb_relate_tag.productid = tb_product.productid
    inner join tb_user ON tb_user.userid=tb_product.createby  
    where tb_product.`delete`=0 and ('.$wherestr.') 
    GROUP BY tb_product.productid ';
    
    $sql='SELECT count(*) as countproduct from (
SELECT
    tb_product.productid
   
    FROM
    tb_relate_tag
    INNER JOIN tb_tag ON tb_tag.tagid = tb_relate_tag.tagid
    INNER JOIN tb_product ON tb_relate_tag.productid = tb_product.productid
    inner join tb_user ON tb_user.userid=tb_product.createby  
    where tb_product.`delete`=0 and ('.$wherestr.')  
    GROUP BY tb_product.productid
     order by tb_product.createdate desc ) tb_product';
    
            $arraycount=$this->db->db_set_1recordrow($sql);
            
            return $arraycount['countproduct'];
            
            
            
            }
            
            
            
            
            
           //end 2-09-2556 
           
           
           
           // 6-09-2556 
           
           function checkmyproductbyuserid($productid,$userid)
           {
           
           $sql="select productid from tb_product where productid=".$productid." and createby=".$userid;
           $checkproduct=$this->db->db_set_1recordrow($sql);
           if($checkproduct['productid'])
           {
           
           return true;
           
           }else
           {
           return false;
           }
           
           
           }
           
           
           
        //end 6-09-2556 
        
            
            function genrefcode()
            {
            // $charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
            $refcode = substr(str_shuffle(str_repeat("0123456789abcdefghijklmnopqrstuvwxyz", 5)), 0, 5);
  
  
        
            $sql="select referid from tb_refer where refcode='".$refcode."'";
            $arraycheck=$this->db->db_set_1recordrow($sql);
            if($arraycheck['referid'])
            {
            
            $refcode=$this->genrefcode();
            }
            
            
        
  
            return $refcode;
            
            
            
            }
            
            function getbank()
            {
            $sql='select * from tb_product_transfer_bank ';
            $arraydata=$this->db->db_set_recordset($sql);
            return $arraydata;
            
            }
            
            
             function getbanktype()
            {
            $sql='select * from tb_product_transfer_type';
            $arraydata=$this->db->db_set_recordset($sql);
            return $arraydata;
            
            }
            
            
            function countpostallfeature()
            {
                $sql='select count(productid) as countproduct from tb_product where tb_product.delete=0 and createdate  BETWEEN "2014-06-01 00:00:00" AND "2014-12-17 23:59:59" ';
                $arrayrow=$this->db->db_set_1recordrow($sql);
                $dtataproduct['Everyting']=$arrayrow['countproduct'];
               
                if(count($this->info['configall']['feature']))
               {
               foreach($this->info['configall']['feature'] as $valuefeature)
               {
                     if($valuefeature['fid'])
                     {
                      $sql='select count(productid) as countproduct from tb_product where tb_product.delete=0 and fid='.$valuefeature['fid'].' and createdate  BETWEEN "2014-06-01 00:00:00" AND "2014-12-17 23:59:59"'; 
                      $arrayrow=$this->db->db_set_1recordrow($sql);
                      $arrayrow['countproduct']=intval($arrayrow['countproduct']);
                      if($arrayrow['countproduct'])
                      {
                      $dtataproduct[$valuefeature['name']]=$arrayrow['countproduct']; 
                      }else
                      {
                      
                      $sql='select count(pointid) as countproduct from tb_product_point where  fid='.$valuefeature['fid']; 
                      $arrayrow=$this->db->db_set_1recordrow($sql);
                      $arrayrow['countproduct']=intval($arrayrow['countproduct']);
                      $dtataproduct[$valuefeature['name']]=$arrayrow['countproduct']; 
                      
                      }
                      
                     
                     }
               
               }
               
               }
            
                return          $dtataproduct;
            
            }
            
            function countmemberall()
            {
            
            $sql='select count(userid) as countuser from tb_user  ';
            
            $arrayrow=$this->db->db_set_1recordrow($sql);
            
            return       $arrayrow['countuser'];
            
            }
            
            
            function counttagall()
            {
            
            
                 $sql='select count(tagid) as counttag from tb_tag  ';
            
            $arrayrow=$this->db->db_set_1recordrow($sql);
            
            return       $arrayrow['counttag'];
            
            }
            
            function getgameexpconfig()
            {
            $sql='SELECT
tb_game_exp_config.gxcid,
tb_game_exp_config.exp,
tb_game_exp_config.`name`
FROM
tb_game_exp_config';
            
            $arraydata=$this->db->db_set_recordset($sql);
            return $arraydata;
            }
            
            function getscoreall()
            {
            
            $sql='SELECT `tb_user`.userid,`tb_user`.username,`tb_user`.displayname,`tb_user`.simgmid,`tb_user`.imgmid,sum(`tb_score_user`.score) as sumall 
FROM `tb_score_user`
INNER JOIN `tb_user` ON `tb_user`.userid = `tb_score_user`.userid
GROUP BY `tb_score_user`.userid
ORDER BY sumall desc 
limit 0,100
';

            $arraydata=$this->db->db_set_recordset($sql);
            if(count($arraydata))
            {
            $k=0;
            foreach($arraydata as $valuedata)
            {
            $arraydata[$k]['imguser']=$this->getimagebyimgmid($valuedata['imgmid']);
            $arraydata[$k]['simguser']=$this->getimagebyimgmid($valuedata['simgmid']);

            $k++;
            
            
            }
            
            }
            
            
            return $arraydata;
            
            }
            
            function getmyscore($userid)
            {
            
            $sql='SELECT `tb_user`.userid,`tb_user`.username,`tb_user`.displayname,`tb_user`.simgmid,`tb_user`.imgmid
FROM `tb_user`
where `tb_user`.userid='.$userid.'
';

            $arraydata=$this->db->db_set_1recordrow($sql);
        
            $arraydata['imguser']=$this->getimagebyimgmid($arraydata['imgmid']);
            $arraydata['simguser']=$this->getimagebyimgmid($arraydata['simgmid']);
            
            
            
             
             
             
             
             $sql='SELECT * from (
SELECT  score, @rank := @rank + 1 AS rank , `tb_score`.userid

FROM (
SELECT sum(`tb_score_user`.score) as score, `tb_user`.userid
FROM `tb_score_user`
INNER JOIN `tb_user` ON `tb_user`.userid = `tb_score_user`.userid
GROUP BY `tb_score_user`.userid
ORDER BY score desc ) tb_score , (SELECT @rank := 0) i   ) q where  userid='.$userid;
$arraydata3=$this->db->db_set_1recordrow($sql);
 if($arraydata3['rank'])
             {
             $arraydata['rank']=$arraydata3['rank'];
             }else
             {
             $arraydata['rank']=0;
             }
             
              if($arraydata3['score'])
             {
             $arraydata['sumall']=$arraydata3['score'];
             }else
             {
             $arraydata['sumall']=0;
             }



            
            
           
            
            
            return $arraydata;
            
            }
            function getdistrictbydisid($disid)
            {
            $sql="SELECT disname FROM `tb_district` where tb_district.disid=$disid";
            $arrayrow=$this->db->db_set_1recordrow($sql);
            return $arrayrow['disname'];
            
            
            }
            
            function gettumbonbytumid($tumid)
            {
            $sql="SELECT tumname FROM `tb_tumbon` where tb_tumbon.tumid=$tumid";
            $arrayrow=$this->db->db_set_1recordrow($sql);
            return $arrayrow['tumname'];
            
            
            }
            function getmodellist()
            {
                             $sql="SHOW TABLES LIKE 'tb_serial_model'";
                 $arraycheck=$this->db->db_set_1recordrow($sql);
                 if(count($arraycheck)==0)
                 {
                 $arraymodel=array();
                 
                 }else
                 {
                 $sql="select * from tb_serial_model";
            $arraymodel=$this->db->db_set_recordset($sql);
                 
                 }
            
            return $arraymodel;
            
            }
            
            function getcartmanage($userid)
            {
            $arraydata=array();
            $sql='select * from tb_product_setting where createby='.$userid;
            $arraydata=$this->db->db_set_1recordrow($sql);
            
            $sql='select * from tb_product_transport where createby='.$userid.' and tb_product_transport.delete=0';
            $arraydata['transportrow']=$this->db->db_set_recordset($sql);
            
            
            $sql='select * from tb_product_transfer where createby='.$userid.' and tb_product_transfer.delete=0';
            $arraydata['transferrow']=$this->db->db_set_recordset($sql);
            
            
            $sql='select * from tb_product_payment where createby='.$userid.' and tb_product_payment.delete=0';
            $arraydata['paymentrow']=$this->db->db_set_recordset($sql);
            
            return $arraydata;
            
            
            }
            
            
           
         
         
        
        }
?>
